class NytimesTopStories::Story
Attributes
byline[RW]
headline[RW]
summary[RW]
url[RW]
Public Class Methods
all()
click to toggle source
# File lib/nytimes_top_stories/story.rb, line 34 def self.all @@all end
clear_all()
click to toggle source
# File lib/nytimes_top_stories/story.rb, line 38 def self.clear_all @@all.clear end
new(story_hash)
click to toggle source
# File lib/nytimes_top_stories/story.rb, line 4 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
new_from_array(array = NytimesTopStories::Scraper.get_top_stories)
click to toggle source
# File lib/nytimes_top_stories/story.rb, line 12 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
Public Instance Methods
open_story()
click to toggle source
# File lib/nytimes_top_stories/story.rb, line 30 def open_story system("open #{@url}") end
puts_story()
click to toggle source
# File lib/nytimes_top_stories/story.rb, line 19 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