class RainJackets::CLI

Attributes

jackets[RW]

Public Instance Methods

call() click to toggle source
# File lib/rain_jackets/cli.rb, line 4
def call
  # Calls Scraper class method that will return array of all jacket objects
  # Store all Jacket instances in CLI's instance variable @jackets
  RainJackets::Scraper.initialize_jacket_objects
  @jackets = RainJackets::Jacket.all
  # Greet user with text input
  puts ""
  puts "Welcome to the Best Women's Rain Jackets Rater!"
  prompt_input
end
get_input() click to toggle source
# File lib/rain_jackets/cli.rb, line 22
def get_input
  input = gets.strip.downcase
  handle_input(input)
end
handle_input(input) click to toggle source

Handles the user pint

# File lib/rain_jackets/cli.rb, line 28
def handle_input(input)
  if input == "all"
    print_list_all

  elsif (1..5).include?(input.to_i)
    print_selected_jacket(input.to_i)

  elsif ['wr', 'b', 'c', 'w', 'd', 'ps'].include?(input)
    print_ratings(input)

  elsif input == "menu"
    print_menu
    get_input

  elsif input == "exit"
    puts "Goodbye! Hope you found your favorite jacket!"
    exit

  else # Make sure that the program doesn't break with unexpected user input
    puts ""
    puts "I don't understand that answer. Please try again!"
  end

  prompt_input # Reinitiate program loop at the end of non-exited handle_input logic
end
print_list_all() click to toggle source

Display all best rain jackets

print_menu() click to toggle source

Display all menu commands/ Define input interface

print_ratings(input) click to toggle source

Display ranked list based on chosen rating category

print_selected_jacket(jacket_number) click to toggle source

Display details of chosen jacket

prompt_input() click to toggle source

Print instructions to screen and prompts user for input

# File lib/rain_jackets/cli.rb, line 16
def prompt_input
  puts "► What would you like to do?"
  puts "► Enter: 'menu' to see all commands / 'exit' to exit program."
  get_input
end
read_rating_input(input) click to toggle source

Convert user input to jacket attribute name string

# File lib/rain_jackets/cli.rb, line 87
def read_rating_input(input)
  # case statement to run multiple conditions against input value
  case input
    when 'wr'
      rating_category = "water_resistance_rating"
    when 'b'
      rating_category = "breathability_rating"
    when 'c'
      rating_category = "comfort_rating"
    when 'w'
      rating_category = "weight_rating"
    when 'd'
      rating_category = "durability_rating"
    when 'ps'
      rating_category = "packed_size_rating"
  end
  rating_category
end