class Gyms::CLI
Attributes
zip[RW]
Public Instance Methods
call()
click to toggle source
# File lib/gyms/cli.rb, line 5 def call title zip = get_zip get_gyms(zip) menu goodbye end
display_detail(input)
click to toggle source
# File lib/gyms/cli.rb, line 72 def display_detail(input) puts "" puts @gyms[input.to_i - 1].name puts @gyms[input.to_i - 1].address1 puts @gyms[input.to_i - 1].address2 puts @gyms[input.to_i - 1].phone puts "" end
get_detail_input()
click to toggle source
# File lib/gyms/cli.rb, line 51 def get_detail_input puts "Type number for gym details or type exit:" input = gets.strip if input == "exit" goodbye elsif input == nil || input.to_i < 0 || input.to_i > 8 || input.count("a-zA-Z") > 0 puts "* * * Invalid entry. Try again. * * * " puts "" get_detail_input else input end end
get_gyms(zip)
click to toggle source
# File lib/gyms/cli.rb, line 19 def get_gyms(zip) @gyms = Gyms::Gym.get_local_gyms(zip) end
get_zip()
click to toggle source
# File lib/gyms/cli.rb, line 33 def get_zip puts "Enter zip code: " input = gets.strip if input.length != 5 || !string_only_numbers?(input) || input == nil puts "* * * Invalid entry. Try again. * * * " puts "" get_zip end input end
goodbye()
click to toggle source
# File lib/gyms/cli.rb, line 81 def goodbye puts "" puts "Enjoy your workout!" puts "" exit end
list_gyms()
click to toggle source
# File lib/gyms/cli.rb, line 66 def list_gyms @gyms.each.with_index(1) do |gym, i| puts "#{i}. #{gym.name}" end end
string_only_numbers?(string)
click to toggle source
# File lib/gyms/cli.rb, line 47 def string_only_numbers?(string) string.scan(/\D/).empty? end
title()
click to toggle source
# File lib/gyms/cli.rb, line 13 def title puts "" puts "Gym Locator" puts "" end