Class: WeatherApiAssignment::WeatherAPIResponse
- Defined in:
- lib/weather_api_assignment/models/weather_api_response.rb
Overview
Weather API overall response model
Instance Attribute Summary collapse
-
#base ⇒ String
This field contains the base.
-
#clouds ⇒ Clouds
This field contains the information about clouds.
-
#cod ⇒ Integer
This information is about cod.
-
#coord ⇒ Coord
This field contains information of longitude and latitude.
-
#dt ⇒ Long
This is current date and time.
-
#id ⇒ Long
This is an identifier.
-
#main ⇒ Main
This field contains the digital stats of current weather.
-
#name ⇒ String
This is the name of city.
-
#sys ⇒ Sys
This field contains information about country, sunrise and sunset.
-
#timezone ⇒ Integer
This field contains information of time zone Id of city.
-
#visibility ⇒ Long
This field contains the visibility value.
-
#weather ⇒ List of Weather
This field contains list of weather information object.
-
#wind ⇒ Wind
This field contains the wind information of current weather.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
Instance Method Summary collapse
-
#initialize(coord = nil, weather = nil, base = nil, main = nil, wind = nil, clouds = nil, dt = nil, sys = nil, id = nil, name = nil, cod = nil, visibility = nil, timezone = nil) ⇒ WeatherAPIResponse
constructor
A new instance of WeatherAPIResponse.
Methods inherited from BaseModel
Constructor Details
#initialize(coord = nil, weather = nil, base = nil, main = nil, wind = nil, clouds = nil, dt = nil, sys = nil, id = nil, name = nil, cod = nil, visibility = nil, timezone = nil) ⇒ WeatherAPIResponse
Returns a new instance of WeatherAPIResponse.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 80 def initialize(coord = nil, weather = nil, base = nil, main = nil, wind = nil, clouds = nil, dt = nil, sys = nil, id = nil, name = nil, cod = nil, visibility = nil, timezone = nil) @coord = coord @weather = weather @base = base @main = main @visibility = visibility @wind = wind @clouds = clouds @dt = dt @sys = sys @id = id @name = name @cod = cod @timezone = timezone end |
Instance Attribute Details
#base ⇒ String
This field contains the base
19 20 21 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 19 def base @base end |
#clouds ⇒ Clouds
This field contains the information about clouds
35 36 37 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 35 def clouds @clouds end |
#cod ⇒ Integer
This information is about cod
55 56 57 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 55 def cod @cod end |
#coord ⇒ Coord
This field contains information of longitude and latitude
11 12 13 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 11 def coord @coord end |
#dt ⇒ Long
This is current date and time
39 40 41 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 39 def dt @dt end |
#id ⇒ Long
This is an identifier
47 48 49 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 47 def id @id end |
#main ⇒ Main
This field contains the digital stats of current weather
23 24 25 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 23 def main @main end |
#name ⇒ String
This is the name of city
51 52 53 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 51 def name @name end |
#sys ⇒ Sys
This field contains information about country, sunrise and sunset
43 44 45 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 43 def sys @sys end |
#timezone ⇒ Integer
This field contains information of time zone Id of city
59 60 61 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 59 def timezone @timezone end |
#visibility ⇒ Long
This field contains the visibility value
27 28 29 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 27 def visibility @visibility end |
#weather ⇒ List of Weather
This field contains list of weather information object
15 16 17 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 15 def weather @weather end |
#wind ⇒ Wind
This field contains the wind information of current weather
31 32 33 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 31 def wind @wind end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 109 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. coord = Coord.from_hash(hash['coord']) if hash['coord'] # Parameter is an array, so we need to iterate through it weather = nil unless hash['weather'].nil? weather = [] hash['weather'].each do |structure| weather << (Weather.from_hash(structure) if structure) end end base = hash['base'] main = Main.from_hash(hash['main']) if hash['main'] wind = Wind.from_hash(hash['wind']) if hash['wind'] clouds = Clouds.from_hash(hash['clouds']) if hash['clouds'] dt = hash['dt'] sys = Sys.from_hash(hash['sys']) if hash['sys'] id = hash['id'] name = hash['name'] cod = hash['cod'] visibility = hash['visibility'] timezone = hash['timezone'] # Create object from extracted values. WeatherAPIResponse.new(coord, weather, base, main, wind, clouds, dt, sys, id, name, cod, visibility, timezone) end |
.names ⇒ Object
A mapping from model property names to API property names.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/weather_api_assignment/models/weather_api_response.rb', line 62 def self.names @_hash = {} if @_hash.nil? @_hash['coord'] = 'coord' @_hash['weather'] = 'weather' @_hash['base'] = 'base' @_hash['main'] = 'main' @_hash['visibility'] = 'visibility' @_hash['wind'] = 'wind' @_hash['clouds'] = 'clouds' @_hash['dt'] = 'dt' @_hash['sys'] = 'sys' @_hash['id'] = 'id' @_hash['name'] = 'name' @_hash['cod'] = 'cod' @_hash['timezone'] = 'timezone' @_hash end |