Class: CommandLineInterface
- Inherits:
-
Object
- Object
- CommandLineInterface
- Defined in:
- lib/Brew_Finder/command_line_interface.rb
Constant Summary collapse
- BASE_PATH =
change this to base api query
"http://beermapping.com/webservice/"- KEY =
"21110efff66df69d91ec3909c0a38eed"
Instance Method Summary collapse
- #add_scores_to_brewery(brewery_id, score_hash) ⇒ Object
- #display_breweries ⇒ Object
-
#display_score(scored_brewery) ⇒ Object
display additional requested brewery info.
- #end_menu ⇒ Object
- #format_location_query(location) ⇒ Object
- #format_score_query(brewery_id) ⇒ Object
-
#get_breweries(formatted_location) ⇒ Object
grab brewery objects from API.
-
#get_brewery_score(formatted_score) ⇒ Object
take the requested brewery and add additional info.
- #get_location_query ⇒ Object
- #get_score_query ⇒ Object
- #return_scores ⇒ Object
- #return_search ⇒ Object
- #root_menu ⇒ Object
- #score_menu ⇒ Object
-
#welcome ⇒ Object
define welcome.
Instance Method Details
#add_scores_to_brewery(brewery_id, score_hash) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 162 def add_scores_to_brewery(brewery_id, score_hash) #puts "brewery_id #{brewery_id.class} score hash #{score_hash}" #Brewery.all.each {|brewery|puts "#{brewery.inspect}"} scored_brewery_array = Brewery.all.select {|brewery| brewery.id == brewery_id.to_i} #puts "#{scored_brewery_array}" scored_brewery = scored_brewery_array[0] #puts "#{scored_brewery.class}" if (score_hash == nil) #puts "nildred" scored_brewery else scored_brewery.add_score_info(score_hash) scored_brewery end end |
#display_breweries ⇒ Object
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 179 def display_breweries Brewery.all.each do |brewery| print "Establishment: ".colorize(:light_yellow) puts "#{brewery.name}".colorize(:yellow) print "ID: ".colorize(:light_green) puts "#{brewery.id}".colorize(:green) puts "#{brewery.street_address}".colorize(:cyan) puts "#{brewery.phone}".colorize(:light_blue) end end |
#display_score(scored_brewery) ⇒ Object
display additional requested brewery info
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 191 def display_score(scored_brewery) if (scored_brewery.overall_score == nil) puts "No scores seem to be available for this brewery." else puts "#{scored_brewery.name}".colorize(:light_magenta) print "Overall score: " puts "#{scored_brewery.overall_score}".colorize(:light_yellow) print "Selection: " puts "#{scored_brewery.selection}".colorize(:light_yellow) print "Service: " puts "#{scored_brewery.service}".colorize(:light_yellow) print "Atmosphere: " puts "#{scored_brewery.atmosphere}".colorize(:light_yellow) print "Number of reviews: " puts"#{scored_brewery.review_count}".colorize(:light_yellow) print "Food (if available): " puts "#{scored_brewery.food}".colorize(:light_yellow) end end |
#end_menu ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 81 def puts "Enter 'list' to show the previous search, 'search' to start a new search, or 'exit' to quit." input = nil while input != "exit" input = gets.chomp case input when /list/ display_breweries when /search/ return_search display_breweries when /exit/ puts "Goodbye!" exit else puts "Sorry, what did you want to do?" end end end |
#format_location_query(location) ⇒ Object
130 131 132 133 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 130 def format_location_query(location) location_query = BASE_PATH + 'loccity/' + KEY + location.downcase location_query end |
#format_score_query(brewery_id) ⇒ Object
144 145 146 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 144 def format_score_query(brewery_id) score_query = BASE_PATH + 'locscore/' + KEY + '/' + brewery_id end |
#get_breweries(formatted_location) ⇒ Object
grab brewery objects from API
148 149 150 151 152 153 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 148 def get_breweries(formatted_location) brewery_array = Brewery_Fetcher.query_api(formatted_location) #create instances of breweries from each brewery fetched Brewery.create_from_collection(brewery_array) #puts "#{brewery_array}" end |
#get_brewery_score(formatted_score) ⇒ Object
take the requested brewery and add additional info
156 157 158 159 160 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 156 def get_brewery_score(formatted_score) #take the brewery instance and give it more attributes scores = Brewery_Fetcher.fetch_score_info(formatted_score) scores end |
#get_location_query ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 115 def get_location_query puts "Please enter the initials of a state you would like to search in:" begin puts "A valid state abbreviation is two letters." state = gets.chomp end until state.match(/^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]))$/) puts "Now enter a city:" begin puts "Any city in #{state}" city = gets.chomp.downcase end until city.match(/^[a-zA-Z]+(?:[\s-][a-zA-Z]+)*$/) city_state_formatted = '/' + city + ',' + state end |
#get_score_query ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 135 def get_score_query puts "Which brewery would you like to learn more about?" begin puts "A valid brewery id is between 4 and 6 digits:" id = gets.chomp end until id.match(/(\d{4,6})/) id end |
#return_scores ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 103 def return_scores id = get_score_query #puts "id:#{id}" formatted_scores = format_score_query(id) scores = get_brewery_score(formatted_scores) #puts "#{scores}" #Brewery.all.each {|brewery| puts "#{brewery.inspect}"} scored_brewery = add_scores_to_brewery(id, scores) #puts "#{scored_brewery.name}" display_score(scored_brewery) end |
#return_search ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 49 def return_search user_location_query = get_location_query #puts "#{user_location_query}" formatted_query = format_location_query(user_location_query) #puts "#{formatted_query}" get_breweries(formatted_query) end |
#root_menu ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 29 def puts "Type 'search' to look for breweries, or 'exit' to quit." input = nil while input != "exit" input = gets.chomp case input when /search/ return_search #Brewery.all.each {|brewery| puts "#{brewery.inspect}"} display_breweries when /exit/ puts "Goodbye!" exit else puts "Sorry, what did you want to do?" end end end |
#score_menu ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 57 def puts "You can enter 'scores' if you would like to see how people have rated a brewery" puts "You can also enter 'search' to start a new search, or enter 'exit' to quit." input = nil while input != "exit" input = gets.chomp case input when /scores/ #Brewery.all.each {|brewery| puts "#{brewery.inspect}"} return_scores when /search/ return_search display_breweries when /exit/ puts "Goodbye!" exit else puts "Sorry, what did you want to do?" end end end |
#welcome ⇒ Object
define welcome
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/Brew_Finder/command_line_interface.rb', line 9 def welcome #first welcome user puts "\e[H\e[2J" puts " o\u00A9\u00BA\u00BA\u00A9oo\u00A9o\u00BA\u00B0\u00A9oo____\n | |____)\n | WELCOME | | |\n | | | |\n | TO | | |\n | | | |\n | B R E W | | |\n | |__|_|\n | FINDER! |____)\n |____________|\n (______________)\n DOC\n root_menu\nend\n" |