Class: Gyms::CLI
- Inherits:
-
Object
- Object
- Gyms::CLI
- Defined in:
- lib/gyms/cli.rb
Instance Attribute Summary collapse
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #call ⇒ Object
- #display_detail(input) ⇒ Object
- #get_detail_input ⇒ Object
- #get_gyms(zip) ⇒ Object
- #get_zip ⇒ Object
- #goodbye ⇒ Object
- #list_gyms ⇒ Object
- #menu ⇒ Object
- #string_only_numbers?(string) ⇒ Boolean
- #title ⇒ Object
Instance Attribute Details
#zip ⇒ Object
Returns the value of attribute zip.
3 4 5 |
# File 'lib/gyms/cli.rb', line 3 def zip @zip end |
Instance Method Details
#call ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/gyms/cli.rb', line 5 def call title zip = get_zip get_gyms(zip) goodbye end |
#display_detail(input) ⇒ Object
72 73 74 75 76 77 78 79 |
# 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 ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
19 20 21 |
# File 'lib/gyms/cli.rb', line 19 def get_gyms(zip) @gyms = Gyms::Gym.get_local_gyms(zip) end |
#get_zip ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
81 82 83 84 85 86 |
# File 'lib/gyms/cli.rb', line 81 def goodbye puts "" puts "Enjoy your workout!" puts "" exit end |
#list_gyms ⇒ Object
66 67 68 69 70 |
# File 'lib/gyms/cli.rb', line 66 def list_gyms @gyms.each.with_index(1) do |gym, i| puts "#{i}. #{gym.name}" end end |
#menu ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/gyms/cli.rb', line 23 def input = nil list_gyms while input != "exit" input = get_detail_input display_detail(input) end end |
#string_only_numbers?(string) ⇒ Boolean
47 48 49 |
# File 'lib/gyms/cli.rb', line 47 def string_only_numbers?(string) string.scan(/\D/).empty? end |
#title ⇒ Object
13 14 15 16 17 |
# File 'lib/gyms/cli.rb', line 13 def title puts "" puts "Gym Locator" puts "" end |