Class: Eatable::CLI
- Inherits:
-
Object
- Object
- Eatable::CLI
- Defined in:
- lib/eatable/cli.rb
Constant Summary collapse
- AREAS =
["New York", "San Francisco", "Los Angeles", "Philadelphia", "Boston", "Chicago", "Washington, DC", "South Florida"]
Instance Attribute Summary collapse
-
#a_input ⇒ Object
Returns the value of attribute a_input.
-
#city_name ⇒ Object
Returns the value of attribute city_name.
-
#n_input ⇒ Object
Returns the value of attribute n_input.
-
#neighborhoods ⇒ Object
Returns the value of attribute neighborhoods.
Instance Method Summary collapse
- #call ⇒ Object
- #greeting ⇒ Object
- #list_restaurants ⇒ Object
- #neighborhood_url ⇒ Object
- #quit ⇒ Object
- #select_area ⇒ Object
- #select_neighborhood ⇒ Object
Instance Attribute Details
#a_input ⇒ Object
Returns the value of attribute a_input.
8 9 10 |
# File 'lib/eatable/cli.rb', line 8 def a_input @a_input end |
#city_name ⇒ Object
Returns the value of attribute city_name.
8 9 10 |
# File 'lib/eatable/cli.rb', line 8 def city_name @city_name end |
#n_input ⇒ Object
Returns the value of attribute n_input.
8 9 10 |
# File 'lib/eatable/cli.rb', line 8 def n_input @n_input end |
#neighborhoods ⇒ Object
Returns the value of attribute neighborhoods.
8 9 10 |
# File 'lib/eatable/cli.rb', line 8 def neighborhoods @neighborhoods end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 |
# File 'lib/eatable/cli.rb', line 11 def call self.greeting self.select_area self.select_neighborhood self.list_restaurants end |
#greeting ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/eatable/cli.rb', line 25 def greeting puts "_" * 85, "\n" puts "Hi there, welcome to Eatable! \u{1f370} \u{1f374}" puts "Restaurants can currently be screened in the following areas:" puts "_" * 85, "\n" AREAS.sort.each_with_index {|a, i| puts "#{i + 1}. #{a}" } end |
#list_restaurants ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/eatable/cli.rb', line 69 def list_restaurants valid_restaurants = Eatable::Scraper.restaurant_scrape(self.neighborhood_url) puts "Here are some potential options!" puts "-" * 31 valid_restaurants.each do |restaurant| puts "\n #{restaurant["name"]}\n #{restaurant["address"]}\n #{restaurant["phone"]}" end puts "_" * 85 puts "\nWould you like to search another area? (Y/n)?" print "=> " input = gets.strip.downcase if input == 'y' self.call else quit end end |
#neighborhood_url ⇒ Object
88 89 90 91 |
# File 'lib/eatable/cli.rb', line 88 def neighborhood_url k = self.neighborhoods.keys self.neighborhoods[k[self.n_input - 1]] end |
#quit ⇒ Object
18 19 20 21 22 |
# File 'lib/eatable/cli.rb', line 18 def quit puts "-" * 24 puts "\nSee you later! \u{2615}" exit(0) end |
#select_area ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/eatable/cli.rb', line 34 def select_area puts "\nWhich area would you like to search? (Please type the number, or 0 to quit.)" print "=> " self.a_input = gets.strip.to_i if self.a_input == 0 self.quit else puts "\nOk! Let's check #{AREAS.sort[self.a_input - 1]}..." puts "_" * 85, "\n" end end |
#select_neighborhood ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/eatable/cli.rb', line 47 def select_neighborhood puts "Available neighborhoods:" puts "-" * 24 @city_name = (AREAS.sort[self.a_input - 1]).downcase.gsub(/\s|,/, "") if @city_name == "newyork" @city_name = "www" end @neighborhoods = Eatable::Scraper.neighborhood_scrape(@city_name) self.neighborhoods.each_with_index {|(k,v), i| puts "#{i + 1}. #{k}"} puts "\nWhere are you thinking of eating? (select the neighborhood number, or 0 to quit)" print "=> " self.n_input = gets.strip.to_i if self.n_input == 0 self.quit else k = self.neighborhoods.keys puts "\nOk! Screening #{k[self.n_input - 1]} restaurant menus... This may take a few minutes..." puts "_" * 90, "\n" end end |