Class: TldrNews::Article

Inherits:
Object
  • Object
show all
Defined in:
lib/tldr_news/article.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headline = nil, contents = nil, url = nil, time = nil) ⇒ Article

Returns a new instance of 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

#contentsObject

Returns the value of attribute contents.



2
3
4
# File 'lib/tldr_news/article.rb', line 2

def contents
  @contents
end

#headlineObject

Returns the value of attribute headline.



2
3
4
# File 'lib/tldr_news/article.rb', line 2

def headline
  @headline
end

#timeObject

Returns the value of attribute time.



2
3
4
# File 'lib/tldr_news/article.rb', line 2

def time
  @time
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/tldr_news/article.rb', line 2

def url
  @url
end

Class Method Details

.allObject



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