Class: HungryVegan::Cli

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCli

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_arrayObject

Returns the value of attribute restaurant_array.



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

def restaurant_array
  @restaurant_array
end

#zipObject

Returns the value of attribute zip.



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

def zip
  @zip
end

#zip_arrayObject

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

#callObject



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
        main_menu_option
end

#exit_programObject



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_restaurantsObject



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

#greetingObject



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

def greeting
    puts "\nWelcome to Hungry Vegan!\n".green
    call
end

#invalid_entryObject



44
45
46
# File 'lib/hungry_vegan/cli.rb', line 44

def invalid_entry
    puts "\nError. Invalid entry.\n".red
end


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/hungry_vegan/cli.rb', line 95

def main_menu_option
    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
        main_menu_option
    end 
end

#select_restaurantObject



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.rating}"
    puts "Phone Number: #{restaurant.phone_number}"
    yellow_line        
end

#show_restaurantsObject



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.rating}"
        puts "Phone Number: #{restaurant.phone_number}"
        yellow_line        
    end 

    def main_menu_option
        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
            main_menu_option
        end 
    end 

end

#yellow_lineObject



40
41
42
# File 'lib/hungry_vegan/cli.rb', line 40

def yellow_line
    puts "------------------------------------------------------------------------------------------------------------------------------------------".yellow
end

#yellow_linesObject



35
36
37
38
# File 'lib/hungry_vegan/cli.rb', line 35

def yellow_lines
    puts "------------------------------------------------------------------------------------------------------------------------------------------".yellow
    puts "------------------------------------------------------------------------------------------------------------------------------------------".yellow    
end