Class: CommandLineInterface

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

Instance Method Summary collapse

Constructor Details

#initializeCommandLineInterface

Returns a new instance of CommandLineInterface.



6
7
8
9
# File 'lib/command_line_interface.rb', line 6

def initialize
    Scraper.gardens_api
    Scraper.garden_hashes
end

Instance Method Details

#all_gardens_detailObject



188
189
190
# File 'lib/command_line_interface.rb', line 188

def all_gardens_detail
    Garden.all.map {|g| index_card(g)}
end

#borough_one_liner(input) ⇒ Object



207
208
209
210
211
212
213
214
215
# File 'lib/command_line_interface.rb', line 207

def borough_one_liner(input)
    alphabatized_boroughs = Garden.filter_by_borough(input).sort_by {|g| g.gardenname}

    alphabatized_boroughs.each do |g|
        puts "~*~ #{"#{g.gardenname}".blue} - #{"#{g.parksid}".magenta}"
        puts " "
    end

end

#citywide_garden_count_reportObject



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/command_line_interface.rb', line 224

def citywide_garden_count_report
    puts " "
    puts "There are a total of #{"#{Garden.all.count} gardens".magenta} in New York City."
    puts " "
    puts "Bronx: #{"#{Garden.filter_by_borough("X").count}".magenta}"
    puts "Queens: #{"#{Garden.filter_by_borough("Q").count}".magenta}"
    puts "Manhattan: #{"#{Garden.filter_by_borough("M").count}".magenta}"
    puts "Brooklyn: #{"#{Garden.filter_by_borough("B").count}".magenta}"
    puts "Staten Island: #{"#{Garden.filter_by_borough("M").count}".magenta}"
    puts " "
    puts "The most vegetative ZIP codes are:" 
    puts " "
    Garden.print_top_zipcodes("all")
    puts " "
end

#find_by_gardenname(input) ⇒ Object



244
245
246
# File 'lib/command_line_interface.rb', line 244

def find_by_gardenname(input)
    Garden.all.detect {|g| g.gardenname == input}
end

#find_by_parksid(input) ⇒ Object



240
241
242
# File 'lib/command_line_interface.rb', line 240

def find_by_parksid(input)
    Garden.all.detect {|g| g.parksid == input}
end

#index_card(garden) ⇒ Object



196
197
198
199
200
201
202
203
204
205
# File 'lib/command_line_interface.rb', line 196

def index_card(garden)
    garden.tap do |g|
        puts "- - - - - - - - - - - - - - - - - - - - - - - - - - "
        puts ""
        puts "  ~*~ #{"#{g.gardenname}".blue} ~*~"
        puts "  #{"#{g.parksid}".magenta} (#{g.status})"
        puts "  #{Garden.translate_borough(g.borough)} - ZIP Code: #{"#{g.zipcode}".yellow}"
        puts ""
    end
end


15
16
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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/command_line_interface.rb', line 15

def menu
    input = ""

        puts " "
        puts "Welcome to the unofficial NYC Parks GreenThumb app".cyan.invert
        puts "What are you interested in learning about today?".cyan.invert
        puts " "

    while input != "9"
        puts "~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~"
        puts " "
        puts "[enter a number]".blue
        puts "#{"[1]".cyan} #{"How many".cyan} gardens are there?"
        puts "#{"[2]".cyan} Show me a (long) list of #{"all gardens".cyan} in the city, please."
        puts "#{"[3]".cyan} Show me a list of the gardens #{"in my borough".cyan}."
        puts "#{"[4]".cyan} Show me a list of the gardens #{"in my ZIP code".cyan}."
        puts "#{"[5]".cyan} I'd like to see #{"a random garden".cyan}. Now."
        puts "#{"[6]".cyan} I know my garden's name or ID number, can I #{"search for it".cyan}?"
        puts "#{"[9]".cyan} Please, let me #{"exit".cyan}."
        puts " "

        input = gets.strip
        case input

            #How many?
            when "1"
                puts " "
                puts "Great question! How would you like me to pull the report?"
                puts " "
                puts "#{"[1]".cyan} in all of New York City"
                puts "#{"[2]".cyan} in my borough"
                puts "#{"[3]".cyan} in my ZIP"

                input = gets.strip

                case input
                    #citywide count
                    when "1"
                        citywide_garden_count_report

                    #borough count
                    when "2"
                        puts " "
                        puts "Ok! Which borough are you in?"
                        puts "#{"[X]".cyan} Bronx"
                        puts "#{"[Q]".cyan} Queens"
                        puts "#{"[M]".cyan} Manhattan"
                        puts "#{"[B]".cyan} Brooklyn"
                        puts "#{"[R]".cyan} Staten Island"

                        input = gets.strip

                        until Garden.all.detect {|g| input == g.borough}
                            puts "That's not a borough. Please try again (maybe without brackets and capitalized?)."
                            input = gets.strip
                        end

                        puts "There are #{"#{Garden.filter_by_borough(input).count}".magenta} in #{"#{Garden.translate_borough(input)}".yellow}."
                        puts "The most vegetative ZIP codes in your borough are:"
                        puts " "
                        Garden.print_top_zipcodes(input)

                        puts " "
                        puts "~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~"

                    #zip count
                    when "3"
                        puts " "
                        puts "Ok! What is your ZIP code?"

                        input = gets.strip
                        
                        until Garden.all.detect {|g| input == g.zipcode}
                            puts "I'm not finding that ZIP code in my system. Please try again. (stuck in a loop? 10031 has some good gardens)."
                            input = gets.strip
                        end

                        puts "There are #{"#{Garden.filter_by_zip(input).count}".magenta} GreenThumb Gardens in #{"#{input}".yellow}."
                        puts ""
                        puts "~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~"
                        zip_one_liner(input)
                end

            #all gardens
            when "2"
                all_gardens_detail
                puts "this is a long report! scroll up to see all of the gardens in New York City #{":)".yellow}"
                puts ""

            #borough report
            when "3"
                puts " "
                puts "Ok! Which borough are you in?"
                puts "#{"[X]".cyan} Bronx"
                puts "#{"[Q]".cyan} Queens"
                puts "#{"[M]".cyan} Manhattan"
                puts "#{"[B]".cyan} Brooklyn"
                puts "#{"[R]".cyan} Staten Island"
                

                input = gets.strip

                until Garden.all.detect {|g| input == g.borough}
                    puts "That's not a borough. Please try again (maybe without brackets and capitalized?)."
                    input = gets.strip
                end

                puts "~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~"
                puts " "
                puts "Here is a list of garden names in your borough."
                borough_one_liner(input)

                puts "#{"this is a long report!".yellow} scroll up to see all of the gardens in #{Garden.translate_borough(input)} #{":)".yellow}"
                puts ""
                puts ""
                puts ""

                puts "#{"Type in the #{"garden ID".magenta} to learn more about a specific location:".cyan}"
                puts ""
                input = gets.strip

                drill_down = find_by_parksid(input)
                index_card(drill_down)

            #zip report
            when "4"
                puts " "
                puts "Ok! What is your ZIP code?"
                input = gets.strip

                until Garden.all.detect {|g| input == g.zipcode}
                    puts "I'm not finding that ZIP code in my system. Please try again. (stuck in a loop? 10031 has some good gardens)."
                    input = gets.strip
                end

                puts "~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~"
                puts ""
                puts "Here's a list of garden names in your borough."
                zip_one_liner(input)
                puts "#{"Type in the #{"garden ID".magenta} to learn more about a specific location:".cyan}"
                input = gets.strip

                drill_down = find_by_parksid(input)
                index_card(drill_down)

            #random report
            when "5"
                random_garden

            #search
            when "6"
                puts "Type in the garden name or ID to pull up more info:"
                input = gets.strip
                search_function(input)
        end
    end
end

#random_gardenObject



192
193
194
# File 'lib/command_line_interface.rb', line 192

def random_garden
    index_card(Garden.all.sample)
end

#runObject



11
12
13
# File 'lib/command_line_interface.rb', line 11

def run
    menu
end

#search_function(input) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/command_line_interface.rb', line 173

def search_function(input)
    if find_by_gardenname(input)
        found_garden = find_by_gardenname(input)
        index_card(found_garden)
    elsif find_by_parksid(input)
        found_garden = find_by_parksid(input)
        index_card(found_garden)
    else
        puts "Sorry, I can't find that park. Are you sure you're spelling it correctly? Try again:"
        input = gets.strip
        search_function(input)
    end
end

#zip_one_liner(input) ⇒ Object



217
218
219
220
221
222
# File 'lib/command_line_interface.rb', line 217

def zip_one_liner(input)
    Garden.filter_by_zip(input).map do |g|
        puts "~*~ #{"#{g.gardenname}".blue} - #{"#{g.parksid}".magenta}"
        puts " "
    end
end