Sha256: e2ba9633fc981c200677b3ebb0f935e7d84af6d999dbe13c9d7930754cc20e2e

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'pry'
class Gyms::CLI
  attr_accessor :zip

  def call
    title
    zip = get_zip
    get_gyms(zip)
    menu
    goodbye
  end

  def title
    puts ""
    puts "Gym Locator"
    puts ""
  end

  def get_gyms(zip)
    @gyms = Gyms::Gym.get_local_gyms(zip)
  end

  def menu
    input = nil
    list_gyms

    while input != "exit"
      input = get_detail_input
      display_detail(input)
    end
  end

  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

  def string_only_numbers?(string)
    string.scan(/\D/).empty?
  end

  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

  def list_gyms
    @gyms.each.with_index(1) do |gym, i|
      puts "#{i}. #{gym.name}"
    end
  end

  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

  def goodbye
    puts ""
    puts "Enjoy your workout!"
    puts ""
    exit
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gyms-0.1.1 lib/gyms/cli.rb
gyms-0.1.0 lib/gyms/cli.rb