class NytimesTopStories::Story

Attributes

byline[RW]
headline[RW]
summary[RW]
url[RW]

Public Class Methods

all() click to toggle source
# File lib/story.rb, line 35
def self.all
  @@all
end
clear_all() click to toggle source
# File lib/story.rb, line 39
def self.clear_all
  @@all.clear
end
new(story_hash) click to toggle source
# 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
new_from_array(array = NytimesTopStories::Scraper.get_top_stories) click to toggle source
# 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

Public Instance Methods

open_story() click to toggle source
# File lib/story.rb, line 31
def open_story
  system("open #{@url}")
end
puts_story() click to toggle source
# 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