class IndieBookstoreFinder::CLI

Public Instance Methods

call() click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 3
def call
  @scraper = IndieBookstoreFinder::Scraper.new
  @states = @scraper.scrape_index_page
  puts "Welcome to Indie Bookstore Finder".cyan
  puts "-----------------------"
  puts "Shopping independent improves our communities!".magenta
  puts "Hit return to get started finding an independent bookseller near you.".magenta
  input = gets
  state_page(@states)
end
cities_page(cities) click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 44
def cities_page(cities)
  puts "We found independent bookstores in these cities in #{@selected_state.name}".cyan
  print_cities(cities)
  cities_page_instructions(cities)
end
cities_page_instructions(cities) click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 56
def cities_page_instructions(cities)
  puts "----------------------------------"
  puts "Please select a city by entering its number from the list and pressing return.".red
  puts "To return to the list of states enter 'states'".red
  puts "To exit enter 'exit'".red
  city_number = gets.strip.downcase
  if city_number == "exit"
    exit_program
  elsif city_number == "states"
    state_page(@states)
  elsif city_number.to_i != 0 && cities[city_number.to_i - 1] != nil
    @selected_city = cities[city_number.to_i - 1]
    store_list_page(@selected_city.stores)
  else
    input_error_message
    cities_page_instructions(cities)
  end
end
exit_program() click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 170
def exit_program
  puts "Thank you for shopping independent! Happy Reading!".cyan
end
input_error_message() click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 174
def input_error_message
  puts "Sorry I don't recognize that input.".red
end
print_cities(cities) click to toggle source
print_states(states) click to toggle source
print_store_details(store) click to toggle source
print_stores(stores) click to toggle source
state_page(states) click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 14
def state_page(states)
  print_states(states)
  state_page_instructions(states)
end
state_page_instructions(states) click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 25
def state_page_instructions(states)
  puts "----------------------------------"
  puts "Please select your state by entering the number from the list and pressing return.".red
  puts "To exit enter 'exit'".red
  state_number = gets.strip.downcase
  if state_number == "exit"
    exit_program
  elsif state_number.to_i != 0 && states[state_number.to_i - 1] != nil
    @selected_state = states[state_number.to_i - 1]
    if @selected_state.cities == []
      @scraper.scrape_state_page(@selected_state)
    end
    cities_page(@selected_state.cities)
  else
    input_error_message
    state_page_instructions(states)
  end
end
store_list_page(stores) click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 75
def store_list_page(stores)
  puts "Here are the indie bookstores in #{@selected_city.name}, #{@selected_state.name}!".cyan
  print_stores(stores)
  store_list_page_instructions(stores)
end
store_list_page_instructions(stores) click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 89
def store_list_page_instructions(stores)
  puts "----------------------------------"
  puts "To see more information about a store by entering its number from the list and pressing return.".red
  puts "To return to the list of cities in #{@selected_state.name} enter 'cities'".red
  puts "To return to the list of states enter 'states'".red
  puts "To exit enter 'exit'".red
  store_number = gets.strip.downcase
  if store_number == "exit"
    exit_program
  elsif store_number == "cities"
    cities_page(@selected_state.cities)
  elsif store_number == "states"
    state_page(@states)
  elsif store_number.to_i != 0 && stores[store_number.to_i - 1] != nil
    @selected_store = stores[store_number.to_i - 1]
    store_page(@selected_store)
  else
    input_error_message
    store_list_page_instructions(stores)
  end
end
store_page(store) click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 111
def store_page(store)
  print_store_details(store)
  store_page_instructions(store)
end
store_page_instructions(store) click to toggle source
# File lib/indie_bookstore_finder/CLI.rb, line 149
def store_page_instructions(store)
  puts "----------------------------------"
  puts "To return to the list of stores in #{@selected_city.name} enter 'stores'".red
  puts "To return to the list of cities in #{@selected_state.name} enter 'cities'".red
  puts "To return to the list of states enter 'states'".red
  puts "To exit enter 'exit'".red
  input = gets.strip.downcase
  if input == "exit"
    exit_program
  elsif input == "cities"
    cities_page(@selected_state.cities)
  elsif input == "states"
    state_page(@states)
  elsif input == "stores"
    store_list_page(@selected_city.stores)
  else
    input_error_message
    store_page(store)
  end
end