Class: MasonellwoodCliAppTwo::StateScraper
- Inherits:
-
Object
- Object
- MasonellwoodCliAppTwo::StateScraper
- Defined in:
- lib/masonellwood_cli_app_two/state-scraper.rb
Instance Attribute Summary collapse
-
#cities ⇒ Object
Returns the value of attribute cities.
-
#name ⇒ Object
Returns the value of attribute name.
-
#state ⇒ Object
Returns the value of attribute state.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #city_weather(input) ⇒ Object
-
#initialize(state) ⇒ StateScraper
constructor
A new instance of StateScraper.
- #scrape_cities ⇒ Object
Constructor Details
#initialize(state) ⇒ StateScraper
Returns a new instance of StateScraper.
4 5 6 |
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 4 def initialize(state) @state = state end |
Instance Attribute Details
#cities ⇒ Object
Returns the value of attribute cities.
2 3 4 |
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 2 def cities @cities end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 2 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
2 3 4 |
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 2 def state @state end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 2 def url @url end |
Instance Method Details
#city_weather(input) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 20 def city_weather(input) input_city = input self.cities.each do |x| citys = x.split(/ : /) downcase_city = citys[0].downcase if downcase_city == input_city html = open("https://www.wunderground.com/#{citys[1]}") #pulls html student_file = Nokogiri::HTML(html) weather_conditions = student_file.css("#curCond .wx-value").text temperature = student_file.css("#curTemp .wx-value").text puts "It looks like you are interested in beautiful #{input_city.capitalize}!" puts "Weather Conditions for Today: #{weather_conditions}" puts "Current Temperature: #{temperature} Degrees Fahrenheit" puts "Check more or the Cities in your area by typing the City name." puts "If you want to see all the Cities again, type Cities." puts "Or type exit." end end end |
#scrape_cities ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 8 def scrape_cities html = open("https://www.wunderground.com/cgi-bin/findweather/getForecast?query=#{@state}") #pulls html student_file = Nokogiri::HTML(html) cities_array = [] student_file.css("tbody tr").each do |x| city = x.css("a").text url = x.search("a").attr("href").value cities_array << "#{city} : #{url}" end @cities = cities_array end |