Class: TechNews::Article
- Inherits:
-
Object
- Object
- TechNews::Article
- Defined in:
- lib/tech_news/article.rb
Instance Attribute Summary collapse
-
#articles ⇒ Object
Returns the value of attribute articles.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
-
.save ⇒ Object
scrape_articles.
-
.scrape_google ⇒ Object
go to Google Technology News, find and scrape articles, instantiate an article.
Instance Attribute Details
#articles ⇒ Object
Returns the value of attribute articles.
3 4 5 |
# File 'lib/tech_news/article.rb', line 3 def articles @articles end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/tech_news/article.rb', line 3 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/tech_news/article.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
5 6 7 |
# File 'lib/tech_news/article.rb', line 5 def self.all @@all = self.save end |
.save ⇒ Object
scrape_articles
9 10 11 12 13 |
# File 'lib/tech_news/article.rb', line 9 def self.save #scrape_articles articles = [] articles << self.scrape_google articles.flatten! end |
.scrape_google ⇒ Object
go to Google Technology News, find and scrape articles, instantiate an article
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tech_news/article.rb', line 15 def self.scrape_google # go to Google Technology News, find and scrape articles, instantiate an article data = [] doc = Nokogiri::HTML(open("https://news.google.com/news/headlines/section/topic/TECHNOLOGY?ned=us&hl=en")) title_array = doc.css("a.nuEeue").select {|element| element['aria-level'] == "2"} title_array.each do |element| article = self.new article.title = element.children.text article.url = element.attributes['href'].value data << article end data end |