class MasonellwoodCliAppTwo::StateScraper
Attributes
cities[RW]
name[RW]
state[RW]
url[RW]
Public Class Methods
new(state)
click to toggle source
# File lib/masonellwood_cli_app_two/state-scraper.rb, line 4 def initialize(state) @state = state @cities = [] end
Public Instance Methods
city_weather(city)
click to toggle source
# File lib/masonellwood_cli_app_two/state-scraper.rb, line 20 def city_weather(city) html = open("https://www.wunderground.com/#{city.url}") #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 #{city.name}!" 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 Number Name." puts "If you want to see all the Cities again, type Cities." puts "Or type exit." end
scrape_cities()
click to toggle source
# File lib/masonellwood_cli_app_two/state-scraper.rb, line 9 def scrape_cities html = open("https://www.wunderground.com/cgi-bin/findweather/getForecast?query=#{@state}") #pulls html student_file = Nokogiri::HTML(html) student_file.css("tbody tr").each do |x| city = x.css("a").text url = x.search("a").attr("href").value new_city = MasonellwoodCliAppTwo::City.new(city, url) @cities << new_city end end