Class: NYCFarmersMarkets::CLI
- Inherits:
-
Object
- Object
- NYCFarmersMarkets::CLI
- Defined in:
- lib/nyc_farmers_markets/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #help ⇒ Object
- #list_all ⇒ Object
- #list_boroughs ⇒ Object
- #market_set ⇒ Object
- #print_by_borough(borough) ⇒ Object
- #print_by_zipcode(zipcode) ⇒ Object
- #start ⇒ Object
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/nyc_farmers_markets/cli.rb', line 3 def call NYCFarmersMarkets::GetMarkets.new.make_markets vesta = "\u26B6".encode('utf-8') flower = "\u2698".encode('utf-8') puts "\n\t #{vesta} Welcome to the Farmers Markets of NYC #{vesta} ".green.underline print "\t"; 15.times { print "#{flower} ".light_blue }; puts "" start end |
#help ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/nyc_farmers_markets/cli.rb', line 77 def help hand = "\u261E".encode('utf-8') keyboard = "\u2328".encode('utf-8') puts "\n #{keyboard} These are the available commands #{keyboard}".light_blue.underline puts "#{hand}list all\t-See a list of all Farmers Markets" puts "#{hand}list boroughs -See a list of boroughs with Farmers Markets" puts "#{hand}[borough name] -See all markets in this borough" puts "#{hand}list zip codes -See a list of zip codes" puts "#{hand}[zip code]\t-See all markets in this zip code" puts "#{hand}help\t\t-See this helpful list of commands!" puts "#{hand}exit\t\t-Say good-bye" end |
#list_all ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/nyc_farmers_markets/cli.rb', line 60 def list_all market_set.all.each do |m| puts "\n#{m.name}".green puts m.street_address == nil ? "-address not available-" : "#{m.street_address}, #{m.borough}, #{m.zipcode}" puts "#{m.additional_info}" unless m.additional_info == nil puts "#{m.website}" unless m.website == nil end end |
#list_boroughs ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/nyc_farmers_markets/cli.rb', line 69 def list_boroughs puts "\n\tBoroughs and Their Number of Farmers Markets".green boroughs_with_num_markets = market_set.list_boroughs.collect do |b| "#{b}(#{market_set.num_markets_in_borough(b)})" end puts boroughs_with_num_markets.join(", ") end |
#market_set ⇒ Object
90 91 92 |
# File 'lib/nyc_farmers_markets/cli.rb', line 90 def market_set NYCFarmersMarkets::Market end |
#print_by_borough(borough) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/nyc_farmers_markets/cli.rb', line 42 def print_by_borough(borough) market_set.find_by_borough(borough).each do |m| puts "\n#{m.name}".green puts "#{m.street_address}, #{m.borough}, #{m.zipcode}" puts "#{m.additional_info}" unless m.additional_info == nil puts "#{m.website}" unless m.website == nil end end |
#print_by_zipcode(zipcode) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/nyc_farmers_markets/cli.rb', line 51 def print_by_zipcode(zipcode) market_set.find_by_zipcode(zipcode).each do |m| puts "\n#{m.name}".green puts "#{m.street_address}, #{m.borough}, #{m.zipcode}" puts "#{m.additional_info}" unless m.additional_info == nil puts "#{m.website}" unless m.website == nil end end |
#start ⇒ Object
13 14 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 |
# File 'lib/nyc_farmers_markets/cli.rb', line 13 def start loop do print "\nWhat would you like to do (type help for more info)? " input = gets.chomp.downcase case input when "list all" list_all when "list boroughs" #puts market_set.list_boroughs.join(" - ") list_boroughs when "bronx", "brooklyn", "manhattan", "queens", "staten island" print_by_borough(input) when "list zip codes" puts market_set.list_zipcodes.join(" - ") when *market_set.list_zipcodes print_by_zipcode(input) when "help" help when "exit" puts "See you next time!" break else puts "Invalid selection!".red end end end |