Class: WeatherApiTask::CityWeather

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/weather_api_task/models/city_weather.rb

Overview

CityWeather Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(message = nil, cod = nil, count = nil, list = nil) ⇒ CityWeather

Returns a new instance of CityWeather.



35
36
37
38
39
40
41
42
43
# File 'lib/weather_api_task/models/city_weather.rb', line 35

def initialize(message = nil,
               cod = nil,
               count = nil,
               list = nil)
  @message = message
  @cod = cod
  @count = count
  @list = list
end

Instance Attribute Details

#codString

TODO: Write general description for this method

Returns:



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

def cod
  @cod
end

#countInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def count
  @count
end

#listList of List

TODO: Write general description for this method

Returns:



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

def list
  @list
end

#messageString

TODO: Write general description for this method

Returns:



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

def message
  @message
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/weather_api_task/models/city_weather.rb', line 46

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  message = hash['message']
  cod = hash['cod']
  count = hash['count']
  # Parameter is an array, so we need to iterate through it
  list = nil
  unless hash['list'].nil?
    list = []
    hash['list'].each do |structure|
      list << (List.from_hash(structure) if structure)
    end
  end

  # Create object from extracted values.
  CityWeather.new(message,
                  cod,
                  count,
                  list)
end

.namesObject

A mapping from model property names to API property names.



26
27
28
29
30
31
32
33
# File 'lib/weather_api_task/models/city_weather.rb', line 26

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['message'] = 'message'
  @_hash['cod'] = 'cod'
  @_hash['count'] = 'count'
  @_hash['list'] = 'list'
  @_hash
end