Class: WeatherApiTask::List
- Defined in:
- lib/weather_api_task/models/list.rb
Overview
List Model.
Instance Attribute Summary collapse
-
#clouds ⇒ Clouds
TODO: Write general description for this method.
-
#coord ⇒ Coord
TODO: Write general description for this method.
-
#dt ⇒ Integer
TODO: Write general description for this method.
-
#id ⇒ Integer
TODO: Write general description for this method.
-
#main ⇒ Main
TODO: Write general description for this method.
-
#name ⇒ String
TODO: Write general description for this method.
-
#rain ⇒ Rain
TODO: Write general description for this method.
-
#snow ⇒ String
TODO: Write general description for this method.
-
#sys ⇒ Sys
TODO: Write general description for this method.
-
#weather ⇒ List of Weather
TODO: Write general description for this method.
-
#wind ⇒ Wind
TODO: Write general description for this method.
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(id = nil, name = nil, coord = nil, main = nil, dt = nil, wind = nil, sys = nil, clouds = nil, weather = nil, rain = nil, snow = nil) ⇒ List
constructor
A new instance of List.
Methods inherited from BaseModel
Constructor Details
#initialize(id = nil, name = nil, coord = nil, main = nil, dt = nil, wind = nil, sys = nil, clouds = nil, weather = nil, rain = nil, snow = nil) ⇒ List
Returns a new instance of List.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/weather_api_task/models/list.rb', line 70 def initialize(id = nil, name = nil, coord = nil, main = nil, dt = nil, wind = nil, sys = nil, clouds = nil, weather = nil, rain = nil, snow = nil) @id = id @name = name @coord = coord @main = main @dt = dt @wind = wind @sys = sys @rain = rain @snow = snow @clouds = clouds @weather = weather end |
Instance Attribute Details
#clouds ⇒ Clouds
TODO: Write general description for this method
47 48 49 |
# File 'lib/weather_api_task/models/list.rb', line 47 def clouds @clouds end |
#coord ⇒ Coord
TODO: Write general description for this method
19 20 21 |
# File 'lib/weather_api_task/models/list.rb', line 19 def coord @coord end |
#dt ⇒ Integer
TODO: Write general description for this method
27 28 29 |
# File 'lib/weather_api_task/models/list.rb', line 27 def dt @dt end |
#id ⇒ Integer
TODO: Write general description for this method
11 12 13 |
# File 'lib/weather_api_task/models/list.rb', line 11 def id @id end |
#main ⇒ Main
TODO: Write general description for this method
23 24 25 |
# File 'lib/weather_api_task/models/list.rb', line 23 def main @main end |
#name ⇒ String
TODO: Write general description for this method
15 16 17 |
# File 'lib/weather_api_task/models/list.rb', line 15 def name @name end |
#rain ⇒ Rain
TODO: Write general description for this method
39 40 41 |
# File 'lib/weather_api_task/models/list.rb', line 39 def rain @rain end |
#snow ⇒ String
TODO: Write general description for this method
43 44 45 |
# File 'lib/weather_api_task/models/list.rb', line 43 def snow @snow end |
#sys ⇒ Sys
TODO: Write general description for this method
35 36 37 |
# File 'lib/weather_api_task/models/list.rb', line 35 def sys @sys end |
#weather ⇒ List of Weather
TODO: Write general description for this method
51 52 53 |
# File 'lib/weather_api_task/models/list.rb', line 51 def weather @weather end |
#wind ⇒ Wind
TODO: Write general description for this method
31 32 33 |
# File 'lib/weather_api_task/models/list.rb', line 31 def wind @wind end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/weather_api_task/models/list.rb', line 95 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. id = hash['id'] name = hash['name'] coord = Coord.from_hash(hash['coord']) if hash['coord'] main = Main.from_hash(hash['main']) if hash['main'] dt = hash['dt'] wind = Wind.from_hash(hash['wind']) if hash['wind'] sys = Sys.from_hash(hash['sys']) if hash['sys'] clouds = Clouds.from_hash(hash['clouds']) if hash['clouds'] # 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 rain = Rain.from_hash(hash['rain']) if hash['rain'] snow = hash['snow'] # Create object from extracted values. List.new(id, name, coord, main, dt, wind, sys, clouds, weather, rain, snow) end |
.names ⇒ Object
A mapping from model property names to API property names.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/weather_api_task/models/list.rb', line 54 def self.names @_hash = {} if @_hash.nil? @_hash['id'] = 'id' @_hash['name'] = 'name' @_hash['coord'] = 'coord' @_hash['main'] = 'main' @_hash['dt'] = 'dt' @_hash['wind'] = 'wind' @_hash['sys'] = 'sys' @_hash['rain'] = 'rain' @_hash['snow'] = 'snow' @_hash['clouds'] = 'clouds' @_hash['weather'] = 'weather' @_hash end |