class SnowReport::CLI

Public Instance Methods

depth() click to toggle source
# File lib/snow_report/cli.rb, line 61
def depth
  puts "----------"
  depth_data = SnowReport::Mountains.all
  depth_data.sort_by! {|obj| -obj.base_depth.to_i}
  depth_data.each_with_index do |resort, i|
    if i < 20
      puts "#{i+1}. #{resort.name} - #{resort.state} - #{resort.base_depth} inches"
    end
  end
end
list_from_state(state) click to toggle source
# File lib/snow_report/cli.rb, line 83
def list_from_state(state)
  puts "----------"
  states_resorts = SnowReport::Mountains.find_all_in_state(state)
  states_resorts.each do |resort|
    puts "#{resort.name} - Base depth: #{resort.base_depth}\" - 72hr Snowfall: #{resort.snowfall}\" - Runs Open: #{resort.runs_open.join("/")}"
  end
end
main_menu() click to toggle source
print_resort(resort) click to toggle source
run() click to toggle source
# File lib/snow_report/cli.rb, line 23
def run
  main_menu
  command = nil
  until command == "exit"
    command = gets.downcase.chomp
    if command == "snowfall"
      #sort by snowfall method
      snowfall
    elsif command == "depth"
      # sort by depth method
      depth
    elsif command == "runs"
      # sort by runs method
      runs
    elsif command == "menu"
      main_menu
    elsif SnowReport::Mountains.find_resort(command)
      print_resort(command)
    elsif SnowReport::Mountains.find_all_in_state(command)
      list_from_state(command)
    else
      puts "Not a valid input ... try again or type 'menu' to see available commands" unless command == "exit"
    end

  end
end
runs() click to toggle source
# File lib/snow_report/cli.rb, line 72
def runs
  puts "----------"
  runs_data = SnowReport::Mountains.all
  runs_data.sort_by! {|obj| -obj.runs_open[0].to_i}
  runs_data.each_with_index do |resort, i|
    if i < 20
      puts "#{i+1}. #{resort.name} - #{resort.state} - #{resort.runs_open.join("/")}"
    end
  end
end
snowfall() click to toggle source
# File lib/snow_report/cli.rb, line 50
def snowfall
  puts "----------"
  snowfall_data = SnowReport::Mountains.all
  snowfall_data.sort_by! {|obj| -obj.snowfall.to_i}
  snowfall_data.each_with_index do |resort, i|
    if i < 20
      puts "#{i+1}. #{resort.name} - #{resort.state} - #{resort.snowfall} inches"
    end
  end
end
start() click to toggle source
# File lib/snow_report/cli.rb, line 3
def start
  rocky_mtn_array = SnowReport::Scraper.scrape_from_web("https://onthesnow.com/rocky-mountain/skireport.html")
  SnowReport::Mountains.new_by_collection(rocky_mtn_array)
  west_coast_array = SnowReport::Scraper.scrape_from_web("https://onthesnow.com/west-coast/skireport.html")
  SnowReport::Mountains.new_by_collection(west_coast_array)
  run
end