Class: Yweather::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/yweather/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(woeid, zipcode, url, hash) ⇒ Response

Returns a new instance of Response.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/yweather/response.rb', line 20

def initialize(woeid, zipcode, url, hash)
  if hash[:rss][:channel][:title] =~ /Error/
    item = hash[:rss][:channel][:item]
    raise YweatherException, "#{hash[:rss][:channel][:title]} :: #{item[:title]} :: #{item[:description]}"
    return
  end
  
  @astronomy = Astronomy.new(hash[:rss][:channel][:astronomy])
  @atmosphere = Atmosphere.new(hash[:rss][:channel][:atmosphere])
  @location = Location.new(hash[:rss][:channel][:location])
  @wind = Wind.new(hash[:rss][:channel][:wind])
  @units = Units.new(hash[:rss][:channel][:units])
  @image = Image.new(hash[:rss][:channel][:image])
  
  item = hash[:rss][:channel][:item]
  @condition = Condition.new(item[:condition])
  @forecasts = []
  item[:forecast].each do |forecast|
    @forecasts << Forecast.new(forecast)
  end
  @latitude = item[:lat]
  @longitude = item[:long]
  @page_url = item[:link]
  @title = item[:title]
  @description = item[:description]
end

Instance Attribute Details

#astronomyObject

Returns the value of attribute astronomy.



4
5
6
# File 'lib/yweather/response.rb', line 4

def astronomy
  @astronomy
end

#atmosphereObject

Returns the value of attribute atmosphere.



5
6
7
# File 'lib/yweather/response.rb', line 5

def atmosphere
  @atmosphere
end

#conditionObject

Returns the value of attribute condition.



6
7
8
# File 'lib/yweather/response.rb', line 6

def condition
  @condition
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/yweather/response.rb', line 7

def description
  @description
end

#forecastsObject

Returns the value of attribute forecasts.



8
9
10
# File 'lib/yweather/response.rb', line 8

def forecasts
  @forecasts
end

#imageObject

Returns the value of attribute image.



9
10
11
# File 'lib/yweather/response.rb', line 9

def image
  @image
end

#latitudeObject

Returns the value of attribute latitude.



10
11
12
# File 'lib/yweather/response.rb', line 10

def latitude
  @latitude
end

#locationObject

Returns the value of attribute location.



11
12
13
# File 'lib/yweather/response.rb', line 11

def location
  @location
end

#longitudeObject

Returns the value of attribute longitude.



12
13
14
# File 'lib/yweather/response.rb', line 12

def longitude
  @longitude
end

#page_urlObject

Returns the value of attribute page_url.



13
14
15
# File 'lib/yweather/response.rb', line 13

def page_url
  @page_url
end

#request_locationObject

Returns the value of attribute request_location.



14
15
16
# File 'lib/yweather/response.rb', line 14

def request_location
  @request_location
end

#request_urlObject

Returns the value of attribute request_url.



15
16
17
# File 'lib/yweather/response.rb', line 15

def request_url
  @request_url
end

#titleObject

Returns the value of attribute title.



16
17
18
# File 'lib/yweather/response.rb', line 16

def title
  @title
end

#unitsObject

Returns the value of attribute units.



17
18
19
# File 'lib/yweather/response.rb', line 17

def units
  @units
end

#windObject

Returns the value of attribute wind.



18
19
20
# File 'lib/yweather/response.rb', line 18

def wind
  @wind
end

Instance Method Details

#atmospheric_conditions(options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/yweather/response.rb', line 47

def atmospheric_conditions(options = {})
  pressure = (@atmosphere.barometer == "steady") ? 
    "#{@atmosphere.barometer} at #{@atmosphere.pressure}#{@units.pressure}" : 
    "#{@atmosphere.pressure}#{@units.pressure} and #{@atmosphere.barometer}"

  h = ::HashWithIndifferentAccess.new({
    :humidity => "#{@atmosphere.humidity}%",
    :visibility => "#{@atmosphere.visibility} #{@units.distance}",
    :pressure => "#{pressure}"
  })

  return_content(h, options[:format])
end

#wind_conditions(options = {}) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/yweather/response.rb', line 61

def wind_conditions(options = {})
  # chill: wind chill in degrees (integer)
  # direction: wind direction, in degrees (integer)
  # speed: wind speed, in the units specified in the speed attribute of the yweather:units element (mph or kph). (integer)
  h = ::HashWithIndifferentAccess.new({
    :chill => "#{@wind.chill}°",
    :direction => "#{@wind.direction}°",
    :speed => "#{@wind.speed} #{@units.speed}"
  })
  return_content(h, options[:format])
end