Class: MdnQuery::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/mdn_query/entry.rb

Overview

An entry of the Mozilla Developer Network documentation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, description, url) ⇒ MdnQuery::Entry

Creates a new entry.

Parameters:

  • title (String)

    the title of the entry

  • description (String)

    a small excerpt of the entry

  • url (String)

    the URL to the entry on the web



13
14
15
16
17
18
# File 'lib/mdn_query/entry.rb', line 13

def initialize(title, description, url)
  @title = title
  @description = description
  @url = url
  @content = nil
end

Instance Attribute Details

#descriptionString (readonly)

Returns:

  • (String)


5
6
7
# File 'lib/mdn_query/entry.rb', line 5

def description
  @description
end

#titleString (readonly)

Returns:

  • (String)


5
6
7
# File 'lib/mdn_query/entry.rb', line 5

def title
  @title
end

#urlString (readonly)

Returns:

  • (String)


5
6
7
# File 'lib/mdn_query/entry.rb', line 5

def url
  @url
end

Instance Method Details

#contentMdnQuery::Document

Returns the content of the entry.

The content is fetched from the Mozilla Developer Network’s documentation. The fetch occurs only once and subsequent calls return the previously fetched content.

Returns:

Raises:



42
43
44
45
# File 'lib/mdn_query/entry.rb', line 42

def content
  return @content unless @content.nil?
  @content = MdnQuery::Document.from_url(url)
end

#openvoid

This method returns an undefined value.

Opens the entry in the default web browser.



30
31
32
# File 'lib/mdn_query/entry.rb', line 30

def open
  Launchy.open(@url)
end

#to_sString

Returns the string representation of the entry.

Returns:

  • (String)


23
24
25
# File 'lib/mdn_query/entry.rb', line 23

def to_s
  "#{title}\n#{description}\n#{url}"
end