Class: HungryVegan::Cli
- Inherits:
-
Object
- Object
- HungryVegan::Cli
- Defined in:
- lib/hungry_vegan/cli.rb
Instance Attribute Summary collapse
-
#restaurant_array ⇒ Object
Returns the value of attribute restaurant_array.
-
#zip ⇒ Object
Returns the value of attribute zip.
-
#zip_array ⇒ Object
Returns the value of attribute zip_array.
Instance Method Summary collapse
- #call ⇒ Object
- #exit_program ⇒ Object
- #get_restaurants ⇒ Object
- #greeting ⇒ Object
-
#initialize ⇒ Cli
constructor
A new instance of Cli.
- #invalid_entry ⇒ Object
- #main_menu_option ⇒ Object
- #select_restaurant ⇒ Object
- #selected_restaurant_info(index) ⇒ Object
- #show_restaurants ⇒ Object
- #yellow_line ⇒ Object
- #yellow_lines ⇒ Object
Constructor Details
#initialize ⇒ Cli
Returns a new instance of Cli.
6 7 8 |
# File 'lib/hungry_vegan/cli.rb', line 6 def initialize @zip_array = [] end |
Instance Attribute Details
#restaurant_array ⇒ Object
Returns the value of attribute restaurant_array.
4 5 6 |
# File 'lib/hungry_vegan/cli.rb', line 4 def restaurant_array @restaurant_array end |
#zip ⇒ Object
Returns the value of attribute zip.
4 5 6 |
# File 'lib/hungry_vegan/cli.rb', line 4 def zip @zip end |
#zip_array ⇒ Object
Returns the value of attribute zip_array.
4 5 6 |
# File 'lib/hungry_vegan/cli.rb', line 4 def zip_array @zip_array end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hungry_vegan/cli.rb', line 15 def call puts "\nType in your 5-digit zip code to get a list of restaurants offering vegan options in your area or type 'exit' to leave the program.\n".light_blue input = nil input = gets.strip yellow_lines if input.downcase == "exit" exit_program exit elsif input.length==5 && input.to_i !=0 @zip=input get_restaurants show_restaurants select_restaurant else invalid_entry end end |
#exit_program ⇒ Object
48 49 50 |
# File 'lib/hungry_vegan/cli.rb', line 48 def exit_program puts "\n\nExiting program. Come back soon!\n\n".green end |
#get_restaurants ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/hungry_vegan/cli.rb', line 52 def get_restaurants if @zip_array.include?(@zip) @restaurant_array= Restaurant.get_matching_restaurants(@zip) else @zip_array<<@zip @restaurant_array= Restaurant.get_restaurants_from_zip(@zip) end end |
#greeting ⇒ Object
10 11 12 13 |
# File 'lib/hungry_vegan/cli.rb', line 10 def greeting puts "\nWelcome to Hungry Vegan!\n".green call end |
#invalid_entry ⇒ Object
44 45 46 |
# File 'lib/hungry_vegan/cli.rb', line 44 def invalid_entry puts "\nError. Invalid entry.\n".red end |
#main_menu_option ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/hungry_vegan/cli.rb', line 95 def puts "\n\nWould you like to enter another zip code? Type 'yes' or 'no'\n\n".light_blue input = gets.strip if input.downcase == "yes" call elsif input.downcase == "no" puts "\nGoodbye. Come back soon!\n".green else invalid_entry end end |
#select_restaurant ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hungry_vegan/cli.rb', line 66 def select_restaurant yellow_lines puts "\nPlease type in the number of the restaurant you would like to view\n".light_blue puts "\nTo exit the program, enter 'exit'.\n".red input= nil input = gets.strip if input.downcase == "exit" exit_program exit elsif input.to_i>0 && input.to_i<=restaurant_array.size selected_restaurant_info(input) else invalid_entry select_restaurant end end |
#selected_restaurant_info(index) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/hungry_vegan/cli.rb', line 83 def selected_restaurant_info(index) if @restaurant_array[index.to_i-1].class==Restaurant restaurant=@restaurant_array[index.to_i-1] end yellow_line puts "Here's more information:" puts "Name: #{restaurant.name}" puts "Rating: #{restaurant.}" puts "Phone Number: #{restaurant.phone_number}" yellow_line end |
#show_restaurants ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/hungry_vegan/cli.rb', line 61 def show_restaurants @restaurant_array.each.with_index(1) do |restaurant,i| puts "#{i}.#{restaurant.name}" end def select_restaurant yellow_lines puts "\nPlease type in the number of the restaurant you would like to view\n".light_blue puts "\nTo exit the program, enter 'exit'.\n".red input= nil input = gets.strip if input.downcase == "exit" exit_program exit elsif input.to_i>0 && input.to_i<=restaurant_array.size selected_restaurant_info(input) else invalid_entry select_restaurant end end def selected_restaurant_info(index) if @restaurant_array[index.to_i-1].class==Restaurant restaurant=@restaurant_array[index.to_i-1] end yellow_line puts "Here's more information:" puts "Name: #{restaurant.name}" puts "Rating: #{restaurant.}" puts "Phone Number: #{restaurant.phone_number}" yellow_line end def puts "\n\nWould you like to enter another zip code? Type 'yes' or 'no'\n\n".light_blue input = gets.strip if input.downcase == "yes" call elsif input.downcase == "no" puts "\nGoodbye. Come back soon!\n".green else invalid_entry end end end |
#yellow_line ⇒ Object
40 41 42 |
# File 'lib/hungry_vegan/cli.rb', line 40 def yellow_line puts "------------------------------------------------------------------------------------------------------------------------------------------".yellow end |
#yellow_lines ⇒ Object
35 36 37 38 |
# File 'lib/hungry_vegan/cli.rb', line 35 def yellow_lines puts "------------------------------------------------------------------------------------------------------------------------------------------".yellow puts "------------------------------------------------------------------------------------------------------------------------------------------".yellow end |