Class: WeatherFinder::CLI
- Inherits:
-
Object
- Object
- WeatherFinder::CLI
- Defined in:
- lib/weather_finder/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#goodbye ⇒ Object
end of menu.
-
#menu(zip_code) ⇒ Object
end of weather ten day.
-
#weather(zip_code) ⇒ Object
call method end.
- #weather_hourly(zip_code) ⇒ Object
-
#weather_ten_day(zip_code) ⇒ Object
end of weather_hourly.
-
#zip_code?(zip_code) ⇒ Boolean
takes all zip codes and compares them to given zip.
Instance Method Details
#call ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 ⇒ Object
end of menu
94 95 96 97 |
# 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) ⇒ Object
end of weather ten day
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/weather_finder/cli.rb', line 68 def (zip_code) input = "" while input.downcase != 'back' || input.downcase != 'exit' puts "Would you like to look at the hourly or 10 day forcast?" puts "Type 'hourly' or '10 day' to choose." puts "type 'back' to choose a different zip code." puts "Or type 'exit' to quit." input = gets.chomp if input.downcase == 'hourly' self.weather_hourly(zip_code) elsif input.downcase == '10 day' || input.downcase == 'ten day' self.weather_ten_day(zip_code) elsif input.downcase == 'back' self.call elsif input.downcase == 'exit' self.goodbye else puts "Do not understand entry." puts "Please enter a valid choice." end#end of if end#end of while end |
#weather(zip_code) ⇒ Object
call method end
22 23 24 25 26 27 28 29 30 31 32 |
# 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.(zip_code) end |
#weather_hourly(zip_code) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
end of weather_hourly
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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) ⇒ Boolean
takes all zip codes and compares them to given zip
99 100 101 102 103 104 105 106 107 108 109 |
# 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 |