Class: WeatherFinder::Scrapper
- Inherits:
-
Object
- Object
- WeatherFinder::Scrapper
- Defined in:
- lib/weather_finder/weather-scrapper.rb
Instance Attribute Summary collapse
-
#feels_like ⇒ Object
Returns the value of attribute feels_like.
-
#hourly_array ⇒ Object
Returns the value of attribute hourly_array.
-
#temp ⇒ Object
Returns the value of attribute temp.
-
#ten_day_arraay ⇒ Object
Returns the value of attribute ten_day_arraay.
-
#uv ⇒ Object
Returns the value of attribute uv.
Class Method Summary collapse
- .basic_scrapper(zip_code) ⇒ Object
- .basic_weather(zip_code) ⇒ Object
- .hourly_weather(zip_code) ⇒ Object
- .ten_day_weather(zip_code) ⇒ Object
Instance Attribute Details
#feels_like ⇒ Object
Returns the value of attribute feels_like.
2 3 4 |
# File 'lib/weather_finder/weather-scrapper.rb', line 2 def feels_like @feels_like end |
#hourly_array ⇒ Object
Returns the value of attribute hourly_array.
2 3 4 |
# File 'lib/weather_finder/weather-scrapper.rb', line 2 def hourly_array @hourly_array end |
#temp ⇒ Object
Returns the value of attribute temp.
2 3 4 |
# File 'lib/weather_finder/weather-scrapper.rb', line 2 def temp @temp end |
#ten_day_arraay ⇒ Object
Returns the value of attribute ten_day_arraay.
2 3 4 |
# File 'lib/weather_finder/weather-scrapper.rb', line 2 def ten_day_arraay @ten_day_arraay end |
#uv ⇒ Object
Returns the value of attribute uv.
2 3 4 |
# File 'lib/weather_finder/weather-scrapper.rb', line 2 def uv @uv end |
Class Method Details
.basic_scrapper(zip_code) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/weather_finder/weather-scrapper.rb', line 9 def self.basic_scrapper(zip_code) doc = Nokogiri::HTML(open("https://weather.com/weather/today/l/#{zip_code}:4:US")) @temp = doc.css(".today_nowcard-temp").text @uv = doc.css(".today_nowcard-hilo div").text @feel_like = doc.css(".deg-feels").text @uv.gsub!("UV Index ", "") end |
.basic_weather(zip_code) ⇒ Object
4 5 6 7 |
# File 'lib/weather_finder/weather-scrapper.rb', line 4 def self.basic_weather(zip_code) self.basic_scrapper(zip_code) [@temp,@uv,@feel_like] end |
.hourly_weather(zip_code) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/weather_finder/weather-scrapper.rb', line 17 def self.hourly_weather(zip_code) @hourly_array = [] doc = Nokogiri::HTML(open("https://weather.com/weather/today/l/#{zip_code}:4:US")) hourly_url = doc.css("ul li a")[1]['href'] hourly_doc = Nokogiri::HTML(open("https://weather.com#{hourly_url}")) hourly_doc.css("tbody tr").each_with_index do |row, i| time = row.css(".dsx-date").text descrip = row.css(".description").text temp = row.css(".temp").text feels = row.css(".feels").text precip = row.css(".precip").text humidity = row.css(".humidity").text wind = row.css(".wind").text @hourly_array[i] = [time,descrip,temp,feels,precip,humidity,wind] end @hourly_array end |
.ten_day_weather(zip_code) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/weather_finder/weather-scrapper.rb', line 39 def self.ten_day_weather(zip_code) @ten_day_array = [] doc = Nokogiri::HTML(open("https://weather.com/weather/today/l/#{zip_code}:4:US")) ten_day_url = doc.css("ul li a")[2]['href'] ten_day_doc = Nokogiri::HTML(open("https://weather.com#{ten_day_url}")) ten_day_doc.css("tbody tr").each_with_index do |row, i| time = row.css(".date-time").text descrip = row.css(".description").text high = row.css(".temp span")[0].text low = row.css(".temp span")[2].text precip = row.css(".precip").text humidity = row.css(".humidity").text wind = row.css(".wind").text @ten_day_array[i] = [time,descrip,high,low,precip,humidity,wind] end @ten_day_array end |