Class: AirQualityIndex::CLI
- Inherits:
-
Object
- Object
- AirQualityIndex::CLI
- Defined in:
- lib/air_quality_index/cli.rb
Instance Method Summary collapse
-
#call ⇒ Object
instantiates a new CLI instance for the program.
-
#data_unavailable_message ⇒ Object
data unavailability message if hours between midnight and 4am EST.
-
#list_options ⇒ Object
lists menu options for user to select from.
-
#menu ⇒ Object
grabs user selection from menu and instantiates appropriate method based on that selection.
-
#return_message ⇒ Object
return message displayed after each menu selection call.
-
#time_check ⇒ Object
check to see if current time is between midnight and 4am EST (Data Unavailable During This Time).
Instance Method Details
#call ⇒ Object
instantiates a new CLI instance for the program
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/air_quality_index/cli.rb', line 4 def call puts '' puts "Welcome to Air Quality Index (AQI) Grabber" puts '' self. self. end |
#data_unavailable_message ⇒ Object
data unavailability message if hours between midnight and 4am EST
82 83 84 85 |
# File 'lib/air_quality_index/cli.rb', line 82 def puts '' puts 'Updates for current conditions are not available between 12:00 a.m. and 4:00a.m. EST.' end |
#list_options ⇒ Object
lists menu options for user to select from
16 17 18 19 20 21 22 23 24 |
# File 'lib/air_quality_index/cli.rb', line 16 def puts <<-DOC.gsub /^\s*/, '' 1. Local AQI Information 2. Top 5 Nationwide AQI Rankings 3. General AQI Information DOC end |
#menu ⇒ Object
grabs user selection from menu and instantiates appropriate method based on that selection
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/air_quality_index/cli.rb', line 27 def puts '' puts "Please enter a numeric selection (1-3), or type exit." puts '' user_input = nil while user_input != 'exit' #gets user input user_input = gets.strip.downcase #based on user input, call appropriate class method case user_input when '1' if self.time_check puts else AirQualityIndex::LocalAQI.new.call_from_zip_code end self. when '2' if self.time_check puts else AirQualityIndex::NationwideAQI.new.call end self. when '3' AirQualityIndex::AQI_Information.new.call self. when 'return' self. self. when 'exit' exit! else puts "I'm sorry. I didn't understand what you meant. Please enter a numeric selection (1-3), or type exit." end end end |
#return_message ⇒ Object
return message displayed after each menu selection call
70 71 72 73 |
# File 'lib/air_quality_index/cli.rb', line 70 def puts "Type 'return' to go back to previous menu, or type 'exit'." puts "" end |
#time_check ⇒ Object
check to see if current time is between midnight and 4am EST (Data Unavailable During This Time)
76 77 78 79 |
# File 'lib/air_quality_index/cli.rb', line 76 def time_check time = Time.now.getlocal('-04:00') time.hour.between?(0,4) end |