Class: NytimesTopStories::Story

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(story_hash) ⇒ Story

Returns a new instance of Story.



5
6
7
8
9
10
11
# File 'lib/story.rb', line 5

def initialize(story_hash)
  @headline = story_hash[:headline].gsub(/â/,"'")
  @byline = story_hash[:byline]
  @summary = story_hash[:summary].gsub(/â/,"'")
  @url = story_hash[:url]
  @@all << self
end

Instance Attribute Details

#bylineObject

Returns the value of attribute byline.



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

def 
  @byline
end

#headlineObject

Returns the value of attribute headline.



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

def headline
  @headline
end

#summaryObject

Returns the value of attribute summary.



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

def summary
  @summary
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



35
36
37
# File 'lib/story.rb', line 35

def self.all
  @@all
end

.clear_allObject



39
40
41
# File 'lib/story.rb', line 39

def self.clear_all
  @@all.clear
end

.new_from_array(array = NytimesTopStories::Scraper.get_top_stories) ⇒ Object



13
14
15
16
17
18
# File 'lib/story.rb', line 13

def self.new_from_array(array = NytimesTopStories::Scraper.get_top_stories)
    self.clear_all
    array.each do |scraped_story|
    story = NytimesTopStories::Story.new(scraped_story) unless scraped_story[:headline].empty? || scraped_story[:byline].empty? || scraped_story[:summary].empty? || scraped_story[:url].empty?
  end
end

Instance Method Details

#open_storyObject



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

def open_story
  system("open #{@url}")
end

#puts_storyObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/story.rb', line 20

def puts_story
  puts @headline
  puts @byline
  puts @summary
  puts "Press enter to open, enter any other input to escape."
  choice = gets.strip
  if choice == ""
    self.open_story
  end
end