Class: Markets::News

Inherits:
Object
  • Object
show all
Defined in:
lib/markets/bus_news.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#authorObject

Returns the value of attribute author.



4
5
6
# File 'lib/markets/bus_news.rb', line 4

def author
  @author
end

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/markets/bus_news.rb', line 4

def content
  @content
end

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/markets/bus_news.rb', line 4

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/markets/bus_news.rb', line 4

def description
  @description
end

Returns the value of attribute link.



4
5
6
# File 'lib/markets/bus_news.rb', line 4

def link
  @link
end

#titleObject

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_storiesObject



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.author = 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_pageObject



7
8
9
# File 'lib/markets/bus_news.rb', line 7

def self.scrape_page
  Nokogiri::HTML(open("https://www.theatlantic.com/business/"))
end