Class: Article
- Inherits:
-
Object
- Object
- Article
- Defined in:
- lib/CLI_Headline_Scraper/Article.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#date ⇒ Object
Returns the value of attribute date.
-
#headline ⇒ Object
Returns the value of attribute headline.
-
#html ⇒ Object
Returns the value of attribute html.
-
#network ⇒ Object
Returns the value of attribute network.
-
#network_name ⇒ Object
Returns the value of attribute network_name.
-
#number_of_comments ⇒ Object
Returns the value of attribute number_of_comments.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .create_with_url(headline, network_name, url) ⇒ Object
- .find_by_headline(headline) ⇒ Object
- .find_by_network_name(network_name) ⇒ Object
- .find_by_summary(word) ⇒ Object
Instance Method Summary collapse
-
#initialize(headline, network_name) ⇒ Article
constructor
headline will eventually be input as a scraper object.
- #populate_metadata ⇒ Object
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
#authors ⇒ Object
Returns the value of attribute authors.
3 4 5 |
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3 def @authors end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3 def date @date end |
#headline ⇒ Object
Returns the value of attribute headline.
3 4 5 |
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3 def headline @headline end |
#html ⇒ Object
Returns the value of attribute html.
3 4 5 |
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3 def html @html end |
#network ⇒ Object
Returns the value of attribute network.
3 4 5 |
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3 def network @network end |
#network_name ⇒ Object
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_comments ⇒ Object
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 |
#summary ⇒ Object
Returns the value of attribute summary.
3 4 5 |
# File 'lib/CLI_Headline_Scraper/Article.rb', line 3 def summary @summary end |
#url ⇒ Object
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
.all ⇒ Object
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_metadata ⇒ Object
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 |