Class: WeatherApiAssignment::Weather

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/weather_api_assignment/models/weather.rb

Overview

This model contains the weather information

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, main = nil, description = nil, icon = nil) ⇒ Weather

Returns a new instance of Weather.



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

def initialize(id = nil,
               main = nil,
               description = nil,
               icon = nil)
  @id = id
  @main = main
  @description = description
  @icon = icon
end

Instance Attribute Details

#descriptionString

This field contains the description of weather type in detail

Returns:



19
20
21
# File 'lib/weather_api_assignment/models/weather.rb', line 19

def description
  @description
end

#iconString

This field contains icon

Returns:



23
24
25
# File 'lib/weather_api_assignment/models/weather.rb', line 23

def icon
  @icon
end

#idInteger

This field contains the identifier

Returns:

  • (Integer)


11
12
13
# File 'lib/weather_api_assignment/models/weather.rb', line 11

def id
  @id
end

#mainString

This field contains the type of weather.

Returns:



15
16
17
# File 'lib/weather_api_assignment/models/weather.rb', line 15

def main
  @main
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
# File 'lib/weather_api_assignment/models/weather.rb', line 46

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash['id']
  main = hash['main']
  description = hash['description']
  icon = hash['icon']

  # Create object from extracted values.
  Weather.new(id,
              main,
              description,
              icon)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['main'] = 'main'
  @_hash['description'] = 'description'
  @_hash['icon'] = 'icon'
  @_hash
end