Class: Threecast::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



2
3
4
5
6
# File 'lib/threecast/cli.rb', line 2

def call
  list_stories
  menu
  goodbye
end

#goodbyeObject



41
42
43
44
# File 'lib/threecast/cli.rb', line 41

def goodbye
  puts "Check back for the latest news."
  exit
end

#list_storiesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/threecast/cli.rb', line 8

def list_stories
  puts ""
  puts "Welcome to Threecast"
  puts "Here are today's top news stories:"
  puts "------------------------------------"
  puts ""

  @news = Threecast::News.today
  @news.each.with_index(1) do |story, i|
    puts "(#{i}) #{story.network} - #{story.date}: #{story.story}"
    puts "" unless i == 3
  end
end


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/threecast/cli.rb', line 22

def menu
  input = nil
  while input != 'exit'
    puts "------------------------------------"
    puts "Enter the story number to open in your browser or exit:"
    input = gets.strip.downcase

    if input.to_i.between?(1,3)
      open_up = @news[input.to_i - 1]
      system("open", "#{open_up.url}")
      list_stories
      menu
    else
      puts "Please enter a number or exit."
    end
  end
  goodbye
end