Class: Weather::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/weather-api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_location, request_url, doc) ⇒ Response

Returns a new instance of Response.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/weather-api/response.rb', line 55

def initialize(request_location, request_url, doc)
  # save the request params
  @request_location = request_location
  @request_url      = request_url

  @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]

  @forecasts = []

  @condition  = Condition.new doc[:item][:condition]

  doc[:item][:forecast].each do |forecast|
    @forecasts << Forecast.new(forecast)
  end

  @latitude    = doc[:item][:lat].to_f
  @longitude   = doc[:item][:long].to_f
  @title       = doc[:item][:title].strip
  @description = doc[:item][:description].strip
end

Instance Attribute Details

#astronomyObject (readonly)

a Weather::Astronomy object containing sunrise and sunset information for the requested location



5
6
7
# File 'lib/weather-api/response.rb', line 5

def astronomy
  @astronomy
end

#atmosphereObject (readonly)

a Weather::Atmosphere object containing the atmosphere information for the requested location



21
22
23
# File 'lib/weather-api/response.rb', line 21

def atmosphere
  @atmosphere
end

#conditionObject (readonly)

a Weather::Condition object detailing the current conditions of the requested location



25
26
27
# File 'lib/weather-api/response.rb', line 25

def condition
  @condition
end

#descriptionObject (readonly)

the HTML summarizing current weather conditions for the requested location



33
34
35
# File 'lib/weather-api/response.rb', line 33

def description
  @description
end

#forecastsObject (readonly)

a collection of Weather::Forecast objects containing high-level forecasted weather for upcoming days



29
30
31
# File 'lib/weather-api/response.rb', line 29

def forecasts
  @forecasts
end

#imageObject (readonly)

a Weather::Image object containing an image icon representing the current weather for the requested location



37
38
39
# File 'lib/weather-api/response.rb', line 37

def image
  @image
end

#latitudeObject (readonly)

the latitude for the requested location



40
41
42
# File 'lib/weather-api/response.rb', line 40

def latitude
  @latitude
end

#locationObject (readonly)

a Weather::Location object containing the geographical names of the requested location



9
10
11
# File 'lib/weather-api/response.rb', line 9

def location
  @location
end

#longitudeObject (readonly)

the longitude for the requested location



43
44
45
# File 'lib/weather-api/response.rb', line 43

def longitude
  @longitude
end

#request_locationObject (readonly)

the location string initially requested of the service.



46
47
48
# File 'lib/weather-api/response.rb', line 46

def request_location
  @request_location
end

#request_urlObject (readonly)

the url with which the Yahoo! Weather service was accessed to build the response



50
51
52
# File 'lib/weather-api/response.rb', line 50

def request_url
  @request_url
end

#titleObject (readonly)

the title of the weather information for the requested location



53
54
55
# File 'lib/weather-api/response.rb', line 53

def title
  @title
end

#unitsObject (readonly)

a Weather::Units object containig the units corresponding to the information contained in the response



13
14
15
# File 'lib/weather-api/response.rb', line 13

def units
  @units
end

#windObject (readonly)

a Weather::Wind object containing the wind information for the requested location



17
18
19
# File 'lib/weather-api/response.rb', line 17

def wind
  @wind
end