Class: MdnQuery::Entry
- Inherits:
-
Object
- Object
- MdnQuery::Entry
- Defined in:
- lib/mdn_query/entry.rb
Overview
An entry of the Mozilla Developer Network documentation.
Instance Attribute Summary collapse
- #description ⇒ String readonly
- #title ⇒ String readonly
- #url ⇒ String readonly
Instance Method Summary collapse
-
#content ⇒ MdnQuery::Document
Returns the content of the entry.
-
#initialize(title, description, url) ⇒ MdnQuery::Entry
constructor
Creates a new entry.
-
#open ⇒ void
Opens the entry in the default web browser.
-
#to_s ⇒ String
Returns the string representation of the entry.
Constructor Details
#initialize(title, description, url) ⇒ MdnQuery::Entry
Creates a new entry.
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
#description ⇒ String (readonly)
5 6 7 |
# File 'lib/mdn_query/entry.rb', line 5 def description @description end |
#title ⇒ String (readonly)
5 6 7 |
# File 'lib/mdn_query/entry.rb', line 5 def title @title end |
#url ⇒ String (readonly)
5 6 7 |
# File 'lib/mdn_query/entry.rb', line 5 def url @url end |
Instance Method Details
#content ⇒ MdnQuery::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.
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 |
#open ⇒ void
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_s ⇒ String
Returns the string representation of the entry.
23 24 25 |
# File 'lib/mdn_query/entry.rb', line 23 def to_s "#{title}\n#{description}\n#{url}" end |