class WeatherFinder::CLI

Public Instance Methods

call() click to toggle source
# File lib/weather_finder/cli.rb, line 3
def call
  input = ""

  while input != "exit"
    puts "What is the zip code you would like to know the weather at?"
    puts "exit to quit"

    input = gets.chomp
    state = self.zip_code?(input)#check zip code

    if state && input.length == 5
      self.weather(input)
    elsif !state && input.downcase != 'exit'
      puts "Invalid Input"
    end
  end# end of while loop
  self.goodbye
end
goodbye() click to toggle source
# File lib/weather_finder/cli.rb, line 94
def goodbye # prints goodbye messages and exits program
  puts "Enjoy your day!"
  exit
end
menu(zip_code) click to toggle source
weather(zip_code) click to toggle source
# File lib/weather_finder/cli.rb, line 22
def weather(zip_code)# prints current weather
  weather = WeatherFinder::Scrapper.basic_weather(zip_code)

  puts "**************************************"
  puts "It is currently #{weather[0]}"
  puts "But it feels like #{weather[2]}"
  puts "With a UV index of #{weather[1]}"
  puts "**************************************"

  self.menu(zip_code)
end
weather_hourly(zip_code) click to toggle source
# File lib/weather_finder/cli.rb, line 34
def weather_hourly(zip_code)

  hourly_weather = WeatherFinder::Scrapper.hourly_weather(zip_code)

  puts "------------------------------------------------------------------------"
  hourly_weather.each do |row|
    print "Time:#{row[0]} "
    print "Description:#{row[1]} "
    print "Temp:#{row[2]} "
    print "Feels Like:#{row[3]} "
    print "Percip:#{row[4]} "
    print "Humidity:#{row[5]} "
    puts  "Wind:#{row[6]} "
    puts "------------------------------------------------------------------------"
  end
end
weather_ten_day(zip_code) click to toggle source
# File lib/weather_finder/cli.rb, line 51
def weather_ten_day(zip_code)

  ten_day_weather = WeatherFinder::Scrapper.ten_day_weather(zip_code)

  puts "------------------------------------------------------------------------"
  ten_day_weather.each do |row|
    print "Day:#{row[0]} "
    print "Description:#{row[1]} "
    print "High:#{row[2]} "
    print "Low:#{row[3]} "
    print "Percip:#{row[4]} "
    print "Humidity:#{row[5]} "
    puts  "Wind:#{row[6]} "
    puts "------------------------------------------------------------------------"
  end
end
zip_code?(zip_code) click to toggle source
# File lib/weather_finder/cli.rb, line 99
def zip_code?(zip_code) #takes all zip codes and compares them to given zip
  valid = false
  zip_path = File.join(File.dirname(__FILE__), '/all_usa_zip.txt')
  File.open(zip_path).each do |zip| #read from file to test valid zip
    if zip.to_i == zip_code.to_i
      valid = true
    end
  end

  valid
end