Class: NytimesTopStories::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



3
4
5
6
7
8
9
# File 'lib/cli.rb', line 3

def call
  puts NytimesTopStories::Scraper.get_date
  puts "Headlines live from NYT:"
  self.display_stories
  self.menu
  self.goodbye
end

#display_storiesObject



11
12
13
14
# File 'lib/cli.rb', line 11

def display_stories
  NytimesTopStories::Story.new_from_array
  NytimesTopStories::Story.all.each.with_index(1) {|story, i| puts "#{i}: #{story.headline}"}
end

#goodbyeObject



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

def goodbye
  puts "The truth is more important now than ever."
  exit(0)
end


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cli.rb', line 16

def menu
  choice = nil
  until choice == "exit"
    puts "Enter story number for more information, or type 'list'/'exit'"
    choice = gets.strip.downcase
    if choice.to_i > 0 && !NytimesTopStories::Story.all[choice.to_i-1].nil?
      story = NytimesTopStories::Story.all[choice.to_i-1]
      story.puts_story
    elsif choice == "list"
      self.call
    elsif choice == "exit"
      break
    else
      puts "Input invalid. Type 'list' or 'exit'."
    end
  end
end