class NationalParks::CLI
Public Class Methods
new()
click to toggle source
# File lib/national_parks/cli.rb, line 3 def initialize welcome NationalParks::Scraper.scrape_find_park_page end
Public Instance Methods
call()
click to toggle source
# File lib/national_parks/cli.rb, line 8 def call list_states state_selection list_parks menu end
list_parks()
click to toggle source
# File lib/national_parks/cli.rb, line 51 def list_parks NationalParks::Scraper.scrape_state_page(@state) if @state.parks.empty? # conditional modifier to prevent redundant scraping and instantiation of state's park objects if that state was previously selected by the user system("clear") puts "\nNational Parks in #{@state.name}:" @state.parks.each.with_index(1) do |park, index| sleep(0.25) puts "\n----------------------------------------------".colorize(:green) puts "#{index}. #{park.name}".colorize(:blue) puts "" puts "Type: #{park.type}" if park.type puts "Location: #{park.location}" if park.location puts "Description: #{park.description}" end end
list_states()
click to toggle source
# File lib/national_parks/cli.rb, line 25 def list_states # states/territories displayed in table format with 2 columns all_rows = [] row = [] NationalParks::State.all.each.with_index(1) do |state, index| row = [] if index.odd? row << "#{index}. #{state.name}" all_rows << row if index.even? || index == NationalParks::State.all.length end table = Terminal::Table.new :title => "U.S. States and Territories", :rows => all_rows puts "\n#{table}" end
state_selection()
click to toggle source
# File lib/national_parks/cli.rb, line 38 def state_selection puts "\nSelect a state or territory by " + "number".underline + " or " + "name".underline + ":" state_input = gets.strip if state_input.to_i.between?(1, NationalParks::State.all.length) @state = NationalParks::State.find_state(state_input) elsif NationalParks::State.find_state_by_name(state_input) @state = NationalParks::State.find_state_by_name(state_input) else puts "Invalid entry.".colorize(:red) state_selection end end
welcome()
click to toggle source
# File lib/national_parks/cli.rb, line 15 def welcome system("clear") puts " ----------------------------------------" puts "| |" puts "| Welcome to National Parks |" puts "| |" puts " ----------------------------------------" puts "\nFind information about the national parks located in any of the U.S. states or territories" end