Class: Article

Inherits:
Object
  • Object
show all
Defined in:
lib/CLI_Headline_Scraper/Article.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headline, network_name) ⇒ Article

headline will eventually be input as a scraper object.



7
8
9
10
11
12
13
14
# File 'lib/CLI_Headline_Scraper/Article.rb', line 7

def initialize(headline, network_name) #headline will eventually be input as a scraper object.
  self.class.all << self
  @network_name = network_name
  @network = Network.find_or_create_by_name(network_name)
  @network.articles << self
   #belongs to network
  @headline = headline
end

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def authors
  @authors
end

#dateObject

Returns the value of attribute date.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def date
  @date
end

#headlineObject

Returns the value of attribute headline.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def headline
  @headline
end

#htmlObject

Returns the value of attribute html.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def html
  @html
end

#networkObject

Returns the value of attribute network.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def network
  @network
end

#network_nameObject

Returns the value of attribute network_name.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def network_name
  @network_name
end

#number_of_commentsObject

Returns the value of attribute number_of_comments.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def number_of_comments
  @number_of_comments
end

#summaryObject

Returns the value of attribute summary.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def summary
  @summary
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3

def url
  @url
end

Class Method Details

.allObject



16
17
18
# File 'lib/CLI_Headline_Scraper/Article.rb', line 16

def self.all
  @@all
end

.create_with_url(headline, network_name, url) ⇒ Object



20
21
22
23
24
# File 'lib/CLI_Headline_Scraper/Article.rb', line 20

def self.create_with_url(headline, network_name, url)
  article = Article.new(headline, network_name)
  article.url = url
  article
end

.find_by_headline(headline) ⇒ Object



27
28
29
# File 'lib/CLI_Headline_Scraper/Article.rb', line 27

def self.find_by_headline(headline)
  self.all.detect{|item| item.headline == headline}
end

.find_by_network_name(network_name) ⇒ Object



31
32
33
# File 'lib/CLI_Headline_Scraper/Article.rb', line 31

def self.find_by_network_name(network_name)
  self.all.select{|item| item.network_name == network_name}
end

.find_by_summary(word) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/CLI_Headline_Scraper/Article.rb', line 35

def self.find_by_summary(word)

  #cycle through all articles.
  #look at each article's summary
  #if summary contains word, add summary to a new array.
  #after finished with all articles, display array.
  self.all.select { |article| article.summary.downcase.include?(word.downcase) }


end

Instance Method Details

#populate_metadataObject



47
48
49
50
51
52
53
54
# File 'lib/CLI_Headline_Scraper/Article.rb', line 47

def ()
  #retreives metadata of reuters article -- right now just time/date.
  #1. Scrapes data from the selected article's url.(separate)
  #3. Uses that data to populate article.authors, article.date_posted, article.text.
  Scraper.reuters_article(self)
  article = Article.find_by_headline(headline)

end