Class: AirQualityIndex::NationwideAQI
- Inherits:
-
Object
- Object
- AirQualityIndex::NationwideAQI
- Defined in:
- lib/air_quality_index/nationwide_aqi.rb
Instance Attribute Summary collapse
-
#fifth_city ⇒ Object
Returns the value of attribute fifth_city.
-
#first_city ⇒ Object
Returns the value of attribute first_city.
-
#fourth_city ⇒ Object
Returns the value of attribute fourth_city.
-
#html ⇒ Object
Returns the value of attribute html.
-
#national_aqi ⇒ Object
Returns the value of attribute national_aqi.
-
#second_city ⇒ Object
Returns the value of attribute second_city.
-
#selected_city ⇒ Object
Returns the value of attribute selected_city.
-
#third_city ⇒ Object
Returns the value of attribute third_city.
-
#todays_date ⇒ Object
sets today’s date for data output.
Instance Method Summary collapse
-
#aqi_message_set(index) ⇒ Object
set aqi messages based off of aqi index ranking.
-
#call ⇒ Object
instantiates a new pull from AirNow.gov for the top 5 current rankings on air pollution.
-
#get_more_info? ⇒ Boolean
asks user if they would like additional information on any of the ranked cities, if so, passes selected city instance to the local_aqi method call and then returns instance.
-
#get_nationwide_data ⇒ Object
sets instance variables for each piece of ranking data from scraped html.
-
#todays_rankings_output ⇒ Object
outputs nationwide ranking information from scraped web data.
Instance Attribute Details
#fifth_city ⇒ Object
Returns the value of attribute fifth_city.
3 4 5 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 3 def fifth_city @fifth_city end |
#first_city ⇒ Object
Returns the value of attribute first_city.
3 4 5 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 3 def first_city @first_city end |
#fourth_city ⇒ Object
Returns the value of attribute fourth_city.
3 4 5 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 3 def fourth_city @fourth_city end |
#html ⇒ Object
Returns the value of attribute html.
3 4 5 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 3 def html @html end |
#national_aqi ⇒ Object
Returns the value of attribute national_aqi.
3 4 5 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 3 def national_aqi @national_aqi end |
#second_city ⇒ Object
Returns the value of attribute second_city.
3 4 5 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 3 def second_city @second_city end |
#selected_city ⇒ Object
Returns the value of attribute selected_city.
3 4 5 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 3 def selected_city @selected_city end |
#third_city ⇒ Object
Returns the value of attribute third_city.
3 4 5 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 3 def third_city @third_city end |
#todays_date ⇒ Object
sets today’s date for data output
28 29 30 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 28 def todays_date @todays_date end |
Instance Method Details
#aqi_message_set(index) ⇒ Object
set aqi messages based off of aqi index ranking
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 81 def (index) case index.to_i when 0..50 "Good" when 51..100 "Moderate" when 101..150 "Unhealthy For Sensitive Groups" when 151..200 "Unhealthy" when 201..300 "Very Unhealthy" when 301 - 500 "Hazardous" else "You are probably too dead to read this from all of the air pollution" end end |
#call ⇒ Object
instantiates a new pull from AirNow.gov for the top 5 current rankings on air pollution
6 7 8 9 10 11 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 6 def call self.get_nationwide_data puts self.todays_rankings_output self.get_more_info? end |
#get_more_info? ⇒ Boolean
asks user if they would like additional information on any of the ranked cities, if so, passes selected city instance to the local_aqi method call and then returns instance
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 101 def get_more_info? puts "Would you like local information for any of the cities listed? Please enter a numerical value 1-5, type 'exit' to end program, or type any other key to return to previous menu." puts "" @selected_city = nil #gets user input user_input = gets.strip.downcase #depending on user input, sets new local aqi instance to city_info variable case user_input when '1' self.selected_city = AirQualityIndex::LocalAQI.new.call_from_ranking(self.first_city) when '2' self.selected_city = AirQualityIndex::LocalAQI.new.call_from_ranking(self.second_city) when '3' self.selected_city = AirQualityIndex::LocalAQI.new.call_from_ranking(self.third_city) when '4' self.selected_city = AirQualityIndex::LocalAQI.new.call_from_ranking(self.fourth_city) when '5' self.selected_city = AirQualityIndex::LocalAQI.new.call_from_ranking(self.fifth_city) when 'exit' exit! end #return city_info if user selected one self.selected_city.local_aqi_return unless self.selected_city.nil? end |
#get_nationwide_data ⇒ Object
sets instance variables for each piece of ranking data from scraped html
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 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 33 def get_nationwide_data #scrape page for top ranking cities @html = AirQualityIndex::Scraper.new.nationwide_aqi_scraper #create and store first rank data @first_city = AirQualityIndex::City.new self.first_city.location_name_full = self.html.search("a.NtnlSummaryCity")[0].text.strip self.first_city.index = self.html.search("div.TabbedPanelsContent").children.css("tr td")[1].children.text.strip self.first_city. = (self.first_city.index) self.first_city.link = html.search("a.NtnlSummaryCity")[0]['href'] #store second rank data @second_city = AirQualityIndex::City.new self.second_city.location_name_full = self.html.search("a.NtnlSummaryCity")[1].text.strip self.second_city.index = self.html.search("div.TabbedPanelsContent").children.css("tr td")[6].children.text.strip self.second_city. = (self.second_city.index) self.second_city.link = html.search("a.NtnlSummaryCity")[1]['href'] #store third rank data @third_city = AirQualityIndex::City.new self.third_city.location_name_full = self.html.search("a.NtnlSummaryCity")[2].text.strip self.third_city.index = self.html.search("div.TabbedPanelsContent").children.css("tr td")[11].children.text.strip self.third_city. = (self.third_city.index) self.third_city.link = html.search("a.NtnlSummaryCity")[2]['href'] #store fourth rank data @fourth_city = AirQualityIndex::City.new self.fourth_city.location_name_full = self.html.search("a.NtnlSummaryCity")[3].text.strip self.fourth_city.index = self.html.search("div.TabbedPanelsContent").children.css("tr td")[16].children.text.strip self.fourth_city. = (self.fourth_city.index) self.fourth_city.link = html.search("a.NtnlSummaryCity")[3]['href'] #store fifth rank data @fifth_city = AirQualityIndex::City.new self.fifth_city.location_name_full = self.html.search("a.NtnlSummaryCity")[4].text.strip self.fifth_city.index = self.html.search("div.TabbedPanelsContent").children.css("tr td")[21].children.text.strip self.fifth_city. = (self.fifth_city.index) self.fifth_city.link = html.search("a.NtnlSummaryCity")[4]['href'] end |
#todays_rankings_output ⇒ Object
outputs nationwide ranking information from scraped web data
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/air_quality_index/nationwide_aqi.rb', line 14 def todays_rankings_output puts "" puts "Nationwide AQI Rankings for #{self.todays_date.month}/#{self.todays_date.day}/#{self.todays_date.year}" puts "" puts " 1. \#{self.first_city.location_name_full} - \#{self.first_city.index} (\#{self.first_city.message})\n 2. \#{self.second_city.location_name_full} - \#{self.second_city.index} (\#{self.second_city.message})\n 3. \#{self.third_city.location_name_full} - \#{self.third_city.index} (\#{self.third_city.message})\n 4. \#{self.fourth_city.location_name_full} - \#{self.fourth_city.index} (\#{self.fourth_city.message})\n 5. \#{self.fifth_city.location_name_full} - \#{self.fifth_city.index} (\#{self.fifth_city.message})\n DOC\nend\n" |