Class: WhatsOnNetflix::CLI
- Inherits:
-
Object
- Object
- WhatsOnNetflix::CLI
- Defined in:
- lib/whats_on_netflix.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
Instance Method Summary collapse
- #back? ⇒ Boolean
-
#exit ⇒ Object
CLI dialogue.
-
#exit? ⇒ Boolean
CLI logic.
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #item_options ⇒ Object
- #list_available_commands ⇒ Object
- #list_options ⇒ Object
- #start ⇒ Object
- #unknown_command ⇒ Object
- #valid_number?(array) ⇒ Boolean
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
7 8 9 10 11 12 13 14 15 |
# File 'lib/whats_on_netflix.rb', line 7 def initialize WhatsOnNetflix::ComingSoon.add_movies WhatsOnNetflix::LeavingSoon.add_movies @input = "" puts "" puts "=============================" puts "Welcome to What's On Netflix!" puts "=============================" end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
5 6 7 |
# File 'lib/whats_on_netflix.rb', line 5 def input @input end |
Instance Method Details
#back? ⇒ Boolean
114 115 116 |
# File 'lib/whats_on_netflix.rb', line 114 def back? @input == "back" end |
#exit ⇒ Object
CLI dialogue
66 67 68 |
# File 'lib/whats_on_netflix.rb', line 66 def exit puts "See you later!" end |
#exit? ⇒ Boolean
CLI logic
110 111 112 |
# File 'lib/whats_on_netflix.rb', line 110 def exit? @input == "exit" end |
#item_options ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/whats_on_netflix.rb', line 70 def puts "" puts "---" puts "Options:" puts "enter another number from the list" puts "back: see a different list" puts "exit: exit" @input = gets.strip end |
#list_available_commands ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/whats_on_netflix.rb', line 80 def list_available_commands puts "" puts "---" puts "Options:" puts "coming-soon: see what's new on Netflix this month" puts "leaving-soon: see what's leaving Netflix this month" puts "exit: exit" puts "" @input = gets.strip end |
#list_options ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/whats_on_netflix.rb', line 91 def puts "" puts "---" puts "Options:" puts "enter a number to see more" puts "back: see a different list" puts "exit: exit" @input = gets.strip end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/whats_on_netflix.rb', line 17 def start while !exit? list_available_commands if @input == "coming-soon" WhatsOnNetflix::ComingSoon.list while !exit? && !back? if valid_number?(WhatsOnNetflix::ComingSoon.all) begin WhatsOnNetflix::ComingSoon.item(@input) rescue puts "" puts "Sorry, we couldn't get info for this title!" end else unknown_command end end elsif @input == "leaving-soon" WhatsOnNetflix::LeavingSoon.list while !exit? && !back? if valid_number?(WhatsOnNetflix::LeavingSoon.all) begin WhatsOnNetflix::LeavingSoon.item(@input) rescue puts "" puts "Sorry, we couldn't get info for this title!" end else unknown_command end end elsif !exit? unknown_command end end exit end |
#unknown_command ⇒ Object
101 102 103 104 105 106 |
# File 'lib/whats_on_netflix.rb', line 101 def unknown_command puts "" puts "I'm sorry, I don't recognize that command." puts "" @input = gets.strip end |
#valid_number?(array) ⇒ Boolean
118 119 120 |
# File 'lib/whats_on_netflix.rb', line 118 def valid_number?(array) @input.to_i > 0 && @input.to_i < (array.length + 1) end |