Class: TivoHelper::CLI

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  TivoHelper::Scraper.new.make_shows
  puts "Welcome to the Tivo Helper!"
  menu
  goodbye
end

#check_genresObject



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/tivo_helper/cli.rb', line 90

def check_genres
  puts "Would you like to look at another genre? Y/N/list"
  answer = gets.chomp
  if answer == "Y"
    genre_search
  elsif answer == "list"
    list_genres
    genre_search
  elsif answer == "N"
    help
  end
end

#check_networksObject



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/tivo_helper/cli.rb', line 103

def check_networks
  puts "Would you like to look at another network? Y/N/list"
  answer = gets.chomp
  if answer == "Y"
    network_search
  elsif answer == "list"
    list_networks
    network_search
  elsif answer == "N"
    help
  end
end

#genre_searchObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tivo_helper/cli.rb', line 66

def genre_search
  puts "Please enter one genre to find shows that match."
  genre_input = gets.chomp
  puts ""
  matched_shows = TivoHelper::Show.find_all_by_genre(genre_input)
  matched_shows.each.with_index(1) do |show, i|
    puts "#{i}. #{show.name} - #{show.genre} - #{show.network}"
  end
  puts ""
  check_genres
end

#goodbyeObject



39
40
41
# File 'lib/tivo_helper/cli.rb', line 39

def goodbye
  puts "Goodbye."
end

#helpObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/tivo_helper/cli.rb', line 43

def help
  puts "How would you like to view your tv premieres?"
  puts "1. By Time"
  puts "2. By Genre"
  puts "3. By Network"
  puts ""
  puts "Please enter the number of your choice."
  puts "Or type exit to leave the program."
  puts ""
end

#list_genresObject



78
79
80
81
82
# File 'lib/tivo_helper/cli.rb', line 78

def list_genres
  puts "Here are your choices for genre:"
  puts "#{TivoHelper::Show.genres.join(", ")}"
  puts ""
end

#list_networksObject



84
85
86
87
88
# File 'lib/tivo_helper/cli.rb', line 84

def list_networks
  puts "Here are your choices for network:"
  puts "#{TivoHelper::Show.networks.join(", ")}"
  puts ""
end

#list_showsObject



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

def list_shows
  TivoHelper::Show.all.each.with_index(1) do |show, i|
    puts "#{i}. #{show.name} - #{show.genre} - #{show.network}"
  end
end


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

def menu
  help
  input = nil
  while input != "exit"
    input = gets.chomp.downcase
    if input == "1"
      list_shows
    elsif input == "2"
      list_genres
      genre_search
    elsif input == "3"
      list_networks
      network_search
    elsif input == "exit"
      puts ""
    elsif input == "help"
      help
    else
      puts "I don't recognize that input. Type help for your options."
    end
  end
end

#network_searchObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tivo_helper/cli.rb', line 54

def network_search
  puts "Please enter one network to find shows that match."
  network_input = gets.chomp
  puts ""
  matched_shows = TivoHelper::Show.find_all_by_network(network_input)
  matched_shows.each.with_index(1) do |show, i|
    puts "#{i}. #{show.name} - #{show.genre} - #{show.network}"
  end
  puts ""
  check_networks
end