Class: TldrNews::Article
- Inherits:
-
Object
- Object
- TldrNews::Article
- Defined in:
- lib/tldr_news/article.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#headline ⇒ Object
Returns the value of attribute headline.
-
#time ⇒ Object
Returns the value of attribute time.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(headline = nil, contents = nil, url = nil, time = nil) ⇒ Article
constructor
A new instance of Article.
Constructor Details
#initialize(headline = nil, contents = nil, url = nil, time = nil) ⇒ Article
5 6 7 8 9 10 11 |
# File 'lib/tldr_news/article.rb', line 5 def initialize(headline = nil, contents = nil, url = nil, time = nil) @url = url @contents = contents @headline = headline @time = time @@all << self end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
2 3 4 |
# File 'lib/tldr_news/article.rb', line 2 def contents @contents end |
#headline ⇒ Object
Returns the value of attribute headline.
2 3 4 |
# File 'lib/tldr_news/article.rb', line 2 def headline @headline end |
#time ⇒ Object
Returns the value of attribute time.
2 3 4 |
# File 'lib/tldr_news/article.rb', line 2 def time @time end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/tldr_news/article.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
13 14 15 |
# File 'lib/tldr_news/article.rb', line 13 def self.all @@all end |
.find(input) ⇒ Object
26 27 28 |
# File 'lib/tldr_news/article.rb', line 26 def self.find(input) @@all[input.to_i - 1] end |
.new_from_html(listing) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/tldr_news/article.rb', line 17 def self.new_from_html(listing) self.new( listing.css('h1.title').text, listing.css('div.summary').text, listing.css('a').attribute('href').value, listing.css('time').text ) end |