Class: AirQualityIndex::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/air_quality_index/cli.rb

Instance Method Summary collapse

Instance Method Details

#callObject

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.list_options
  self.menu

end

#data_unavailable_messageObject

data unavailability message if hours between midnight and 4am EST



82
83
84
85
# File 'lib/air_quality_index/cli.rb', line 82

def data_unavailable_message
  puts ''
  puts 'Updates for current conditions are not available between 12:00 a.m. and 4:00a.m. EST.'
end

#list_optionsObject

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 list_options
  puts <<-DOC.gsub /^\s*/, ''

  1. Local AQI Information
  2. Top 5 Nationwide AQI Rankings
  3. General AQI Information

  DOC
end

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 menu

  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 data_unavailable_message
      else
        AirQualityIndex::LocalAQI.new.call_from_zip_code
      end
      self.return_message
    when '2'
      if self.time_check
        puts data_unavailable_message
      else
        AirQualityIndex::NationwideAQI.new.call
      end
      self.return_message
    when '3'
      AirQualityIndex::AQI_Information.new.call
      self.return_message
    when 'return'
      self.list_options
      self.menu
    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_messageObject

return message displayed after each menu selection call



70
71
72
73
# File 'lib/air_quality_index/cli.rb', line 70

def return_message
  puts "Type 'return' to go back to previous menu, or type 'exit'."
  puts ""
end

#time_checkObject

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