lib/weather-api/response.rb in weather-api-1.0.1 vs lib/weather-api/response.rb in weather-api-1.1.0
- old
+ new
@@ -50,36 +50,32 @@
attr_reader :request_url
# the title of the weather information for the requested location
attr_reader :title
- def initialize(request_location, request_url, doc)
+ def initialize request_location, request_url, doc
# save the request params
@request_location = request_location
@request_url = request_url
- # parse the xml element to get response data
- root = doc.xpath('/rss/channel').first
+ @astronomy = Astronomy.new doc[:astronomy]
+ @location = Location.new doc[:location]
+ @units = Units.new doc[:units]
+ @wind = Wind.new doc[:wind]
+ @atmosphere = Atmosphere.new doc[:atmosphere]
+ @image = Image.new doc[:item][:description]
- @astronomy = Weather::Astronomy.new(root.xpath('yweather:astronomy').first)
- @location = Weather::Location.new(root.xpath('yweather:location').first)
- @units = Weather::Units.new(root.xpath('yweather:units').first)
- @wind = Weather::Wind.new(root.xpath('yweather:wind').first)
- @atmosphere = Weather::Atmosphere.new(root.xpath('yweather:atmosphere').first)
- @image = Weather::Image.new(root.xpath('image').first)
-
- item = root.xpath('item').first
@forecasts = []
- @condition = Weather::Condition.new(item.xpath('yweather:condition').first)
+ @condition = Condition.new doc[:item][:condition]
- item.xpath('yweather:forecast').each do |forecast|
- @forecasts << Weather::Forecast.new(forecast)
+ doc[:item][:forecast].each do |forecast|
+ @forecasts << Forecast.new(forecast)
end
- @latitude = item.xpath('geo:lat').first.content.to_f
- @longitude = item.xpath('geo:long').first.content.to_f
- @title = item.xpath('title').first.content
- @description = item.xpath('description').first.content
+ @latitude = doc[:item][:lat].to_f
+ @longitude = doc[:item][:long].to_f
+ @title = doc[:item][:title]
+ @description = doc[:item][:description]
end
end
end