Class: SfCoffee::CLI
- Inherits:
-
Object
- Object
- SfCoffee::CLI
- Defined in:
- lib/sf_coffee/cli.rb
Constant Summary collapse
- ZIP_CODES =
[94102, 94103, 94104, 94105, 94107, 94108, 94109, 94110, 94111, 94112, 94114, 94115, 94116, 94117, 94118, 94121, 94122, 94123, 94124, 94127, 94129, 94130, 94131, 94132, 94133, 94134, 94158]
Instance Method Summary collapse
- #call ⇒ Object
- #finish_session ⇒ Object
- #goodbye ⇒ Object
- #greeting ⇒ Object
- #menu ⇒ Object
- #print_menu ⇒ Object
- #valid_zipcode?(input) ⇒ Boolean
Instance Method Details
#call ⇒ Object
13 14 15 16 17 |
# File 'lib/sf_coffee/cli.rb', line 13 def call greeting goodbye end |
#finish_session ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sf_coffee/cli.rb', line 33 def finish_session puts "To finish your session type" + " exit.".red + " To return to the main menu type" + " menu".red + "." input = gets.strip.downcase while input != "exit" && input !="menu" puts "Oops, something went wrong. Please try again.".red input = gets.strip.downcase end if input == "menu" self. else end end |
#goodbye ⇒ Object
115 116 117 |
# File 'lib/sf_coffee/cli.rb', line 115 def goodbye puts "Thank you for using SF coffee fnder!".yellow end |
#greeting ⇒ Object
19 20 21 22 |
# File 'lib/sf_coffee/cli.rb', line 19 def greeting puts "\n" puts "Welcome to San Francisco coffee finder!" end |
#menu ⇒ Object
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 |
# File 'lib/sf_coffee/cli.rb', line 50 def self. input = gets.strip until input == "exit" || input =="menu" || input =="1" || input =="2" || input =="3" || valid_zipcode?(input) == true puts "Oops, something went wrong. Please choose a number from the menu, or enter a valid San Francisco zipcode".red input = gets.strip end if input == "menu" self. end if input == "1" # lists all Starbucks locations puts "Here is what we found for your request:".blue SfCoffee::Scraper.starbucks.each_with_index do |store, index| puts "#{index+1}. Store name: ".yellow + "#{store[:name]}".yellow puts "Address: #{store[:address]}, #{store[:zip_code]}".white puts "Phone: #{store[:phone]}".white end self.finish_session elsif input == "2" #lists all Peet's Coffee and Tea locations puts "Here is what we found for your request:".blue SfCoffee::Scraper.peets.each_with_index do |store, index| puts "#{index+1}. Store name: ".yellow + "#{store[:name]}".yellow puts "Address: #{store[:address]}, #{store[:zip_code]}".white puts "Phone: #{store[:phone]}".white end self.finish_session elsif input == "3" #lists all Philz Coffee locations puts "Here is what we found for your request:".blue SfCoffee::Scraper.philz.each_with_index do |store, index| puts "#{index+1}. Store name: ".yellow + "#{store[:name]}".yellow puts "Address: #{store[:address]}, #{store[:zip_code]}".white puts "Phone: #{store[:phone]}".white end self.finish_session elsif valid_zipcode?(input) #prints the coffee shops in the area" stores_with_zip = [] SfCoffee::Scraper.starbucks.each do |store| if store[:zip_code] == input stores_with_zip << store end end SfCoffee::Scraper.peets.each do |store| if store[:zip_code] == input stores_with_zip << store end end SfCoffee::Scraper.philz.each do |store| if store[:zip_code] == input stores_with_zip << store end end puts "Here is what we found for your request:".blue stores_with_zip.each_with_index do |store, index| puts "#{index+1}. Store name: ".yellow + "#{store[:name]}".yellow puts "Address: #{store[:address]}, #{store[:zip_code]}".white puts "Phone: #{store[:phone]}".white end self.finish_session end end |
#print_menu ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/sf_coffee/cli.rb', line 24 def puts "List all of the locations for your favorite coffee company by entering 1, 2, or 3:" puts "\t1. Starbucks".yellow puts "\t2. Peet's Coffee and Tea".yellow puts "\t3. Philz Coffee".yellow puts "OR" puts "Find the nearest coffeeshop, by entering your ZIP Code:" end |
#valid_zipcode?(input) ⇒ Boolean
46 47 48 |
# File 'lib/sf_coffee/cli.rb', line 46 def valid_zipcode?(input) ZIP_CODES.include?(input.to_i) end |