Class: MasonellwoodCliAppTwo::StateScraper

Inherits:
Object
  • Object
show all
Defined in:
lib/masonellwood_cli_app_two/state-scraper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ StateScraper

Returns a new instance of StateScraper.



4
5
6
7
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 4

def initialize(state)
  @state = state
  @cities = []
end

Instance Attribute Details

#citiesObject

Returns the value of attribute cities.



2
3
4
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 2

def cities
  @cities
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 2

def name
  @name
end

#stateObject

Returns the value of attribute state.



2
3
4
# File 'lib/masonellwood_cli_app_two/state-scraper.rb', line 2

def state
  @state
end

#urlObject

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(city) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# 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_citiesObject



9
10
11
12
13
14
15
16
17
18
# 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