Class: NytimesTopStories::Story
- Inherits:
-
Object
- Object
- NytimesTopStories::Story
- Defined in:
- lib/story.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#byline ⇒ Object
Returns the value of attribute byline.
-
#headline ⇒ Object
Returns the value of attribute headline.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .clear_all ⇒ Object
- .new_from_array(array = NytimesTopStories::Scraper.get_top_stories) ⇒ Object
Instance Method Summary collapse
-
#initialize(story_hash) ⇒ Story
constructor
A new instance of Story.
- #open_story ⇒ Object
- #puts_story ⇒ Object
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
#byline ⇒ Object
Returns the value of attribute byline.
3 4 5 |
# File 'lib/story.rb', line 3 def @byline end |
#headline ⇒ Object
Returns the value of attribute headline.
3 4 5 |
# File 'lib/story.rb', line 3 def headline @headline end |
#summary ⇒ Object
Returns the value of attribute summary.
3 4 5 |
# File 'lib/story.rb', line 3 def summary @summary end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/story.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
35 36 37 |
# File 'lib/story.rb', line 35 def self.all @@all end |
.clear_all ⇒ Object
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_story ⇒ Object
31 32 33 |
# File 'lib/story.rb', line 31 def open_story system("open #{@url}") end |
#puts_story ⇒ Object
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 |