Class: WhatsOn::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/whats_on/cli.rb', line 4

def name
  @name
end

#showsObject

Returns the value of attribute shows.



4
5
6
# File 'lib/whats_on/cli.rb', line 4

def shows
  @shows
end

Instance Method Details

#callObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/whats_on/cli.rb', line 6

def call
  @shows=WhatsOn::Show.all
  puts "What's on tv tonight? Find a show to watch!"
  puts ''
  puts "Maybe this one?\nFeatured Show:"
  list_suggestion
  puts ''
  menu
  goodbye
end

#goodbyeObject



30
31
32
# File 'lib/whats_on/cli.rb', line 30

def goodbye
  puts "Happy viewing! Goodbye!"
end

#list_showsObject



17
18
19
20
21
22
# File 'lib/whats_on/cli.rb', line 17

def list_shows
  @shows.each.with_index(1) do |show, i|
    puts "#{i}. #{show[:name]} - #{show[:airing]}"
  end
  puts "Enter the show number for details"
end

#list_suggestionObject



24
25
26
27
28
# File 'lib/whats_on/cli.rb', line 24

def list_suggestion
  dice = rand(0..4)
  puts "#{@shows[dice][:name]} - #{@shows[dice][:airing]} \n#{@shows[dice][:description]}\n"
  puts ''
end


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/whats_on/cli.rb', line 34

def menu
  puts "What would you like to do next?"
  puts "Enter List to list all shows, Suggest to suggest a featured show or type exit"
  input = nil
  until input == "exit"
    input = gets.strip.downcase
    if input.to_i > 0
      puts "#{@shows[input.to_i-1][:name]} - #{@shows[input.to_i-1][:airing]} \n#{@shows[input.to_i-1][:description]}"
    elsif input == "list"
      list_shows
    elsif input == "suggest"
      list_suggestion
    elsif input == "exit"
    else
        puts "Hmm.  Please check entry and try again."
    end
  end
end