Class: WeatherApiTask::List

Inherits:
BaseModel show all
Defined in:
lib/weather_api_task/models/list.rb

Overview

List Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

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

#cloudsClouds

TODO: Write general description for this method

Returns:



47
48
49
# File 'lib/weather_api_task/models/list.rb', line 47

def clouds
  @clouds
end

#coordCoord

TODO: Write general description for this method

Returns:



19
20
21
# File 'lib/weather_api_task/models/list.rb', line 19

def coord
  @coord
end

#dtInteger

TODO: Write general description for this method

Returns:

  • (Integer)


27
28
29
# File 'lib/weather_api_task/models/list.rb', line 27

def dt
  @dt
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


11
12
13
# File 'lib/weather_api_task/models/list.rb', line 11

def id
  @id
end

#mainMain

TODO: Write general description for this method

Returns:



23
24
25
# File 'lib/weather_api_task/models/list.rb', line 23

def main
  @main
end

#nameString

TODO: Write general description for this method

Returns:



15
16
17
# File 'lib/weather_api_task/models/list.rb', line 15

def name
  @name
end

#rainRain

TODO: Write general description for this method

Returns:

  • (Rain)


39
40
41
# File 'lib/weather_api_task/models/list.rb', line 39

def rain
  @rain
end

#snowString

TODO: Write general description for this method

Returns:



43
44
45
# File 'lib/weather_api_task/models/list.rb', line 43

def snow
  @snow
end

#sysSys

TODO: Write general description for this method

Returns:



35
36
37
# File 'lib/weather_api_task/models/list.rb', line 35

def sys
  @sys
end

#weatherList of Weather

TODO: Write general description for this method

Returns:



51
52
53
# File 'lib/weather_api_task/models/list.rb', line 51

def weather
  @weather
end

#windWind

TODO: Write general description for this method

Returns:



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

.namesObject

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