Class: Markets::News
- Inherits:
-
Object
- Object
- Markets::News
- Defined in:
- lib/markets/bus_news.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#content ⇒ Object
Returns the value of attribute content.
-
#date ⇒ Object
Returns the value of attribute date.
-
#description ⇒ Object
Returns the value of attribute description.
-
#link ⇒ Object
Returns the value of attribute link.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
4 5 6 |
# File 'lib/markets/bus_news.rb', line 4 def @author end |
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/markets/bus_news.rb', line 4 def content @content end |
#date ⇒ Object
Returns the value of attribute date.
4 5 6 |
# File 'lib/markets/bus_news.rb', line 4 def date @date end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/markets/bus_news.rb', line 4 def description @description end |
#link ⇒ Object
Returns the value of attribute link.
4 5 6 |
# File 'lib/markets/bus_news.rb', line 4 def link @link end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/markets/bus_news.rb', line 4 def title @title end |
Class Method Details
.create_stories ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/markets/bus_news.rb', line 17 def self.create_stories stories = [] scrape_page.css("ul.river li.article.blog-article").each do |article| story = self.new story.title = article.css("h2.hed").text story.content = article.css("p.dek.has-dek").text story. = article.css("ul li.byline a").text story.date = article.css(".date").text, story.link = article.css("a").attribute('href').value stories << story end stories end |
.get_story(link) ⇒ Object
11 12 13 14 15 |
# File 'lib/markets/bus_news.rb', line 11 def self.get_story(link) doc = Nokogiri::HTML(open(link)).css("ul.river") doc.children.each { |c| c.remove if c.name == 'div'} doc.text.strip end |
.scrape_page ⇒ Object
7 8 9 |
# File 'lib/markets/bus_news.rb', line 7 def self.scrape_page Nokogiri::HTML(open("https://www.theatlantic.com/business/")) end |