class NationalParks::CLI

Constants

BASE_PATH

Public Instance Methods

call() click to toggle source

Basic Run #

# File lib/national_parks/CLI.rb, line 8
def call
  welcome
  NationalParks::State.scrape_states
  list_states
end
display_parks() click to toggle source
# File lib/national_parks/CLI.rb, line 95
def display_parks
  puts ""
  puts "==================================================".colorize(:yellow)
  puts ""
  puts "#{@parks[@i].name.upcase} #{@parks[@i].type.upcase}"
  puts "-#{@parks[@i].location}-"
  puts "#{@parks[@i].description}"
  puts ""
  puts "  - Type 'parks' to return to the parks list."
  puts "  - Type 'states' to return to the states list."
  puts "  - Type 'exit' to leave"
end
goodbye() click to toggle source
# File lib/national_parks/CLI.rb, line 24
def goodbye
  puts ""
  puts "  Hope to see you again soon!"
  puts ""
  exit
end
list_parks(choice) click to toggle source

Park Methods #

# File lib/national_parks/CLI.rb, line 61
def list_parks(choice)
  @chosen_state = BASE_PATH + @states[choice].url

  puts ""
  puts "==".colorize(:green) + "#{NationalParks::Park.state_name(@chosen_state)}" + "==".colorize(:green)
  @parks = NationalParks::Park.all(@chosen_state)
  @parks.each.with_index(1) {|park, i| puts " #{i}. #{park.name}"}
  park_menu
end
list_states() click to toggle source

State Methods #

# File lib/national_parks/CLI.rb, line 33
def list_states
  @states = NationalParks::State.all
  puts ""
  @states.each.with_index(1) {|state, i| puts " #{i}. #{state.name}"}
  state_menu
end
park_menu() click to toggle source
# File lib/national_parks/CLI.rb, line 71
def park_menu
  puts "Please pick a park or monument by number for more information."
  puts "  - Type 'states' to return to the states list."
  puts "  - Type 'exit' to leave."

  input = nil
  while input != "exit"
    input = gets.strip.downcase

    if input.to_i > 0 && input.to_i <= @parks.length
      @i = input.to_i-1
      display_parks
    elsif input == "parks"
      list_parks(@state_i)
    elsif input == "states"
      list_states
    elsif input == "exit"
      goodbye
    else
      puts "Please select a valid park or monument."
    end
  end
end
state_menu() click to toggle source
# File lib/national_parks/CLI.rb, line 40
def state_menu
  puts "Please pick a US state or territory by number."
  puts "  - Type 'exit' to leave."
  input = nil

  while input != "exit"
    input = gets.strip.downcase

    if input.to_i > 0 && input.to_i <= @states.length
      @state_i = input.to_i-1
      list_parks(@state_i)
    elsif input == "exit"
      goodbye
    else
      puts "Please select a valid state or territory."
    end
  end
end
welcome() click to toggle source

Greetings #

# File lib/national_parks/CLI.rb, line 16
def welcome
  puts ""
  puts "                                      /\\ ".colorize(:green)
  puts "                                     //\\\\".colorize(:green)
  puts "Welcome to the National Park Service!" + " ||".colorize(:black)
  sleep(1)
end