Class: WeatherApiAssignment::Sys

Inherits:
BaseModel show all
Defined in:
lib/weather_api_assignment/models/sys.rb

Overview

This model contains the country, sunset and sunrise information.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(sunrise = nil, sunset = nil, type = nil, id = nil, message = nil, country = nil) ⇒ Sys

Returns a new instance of Sys.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/weather_api_assignment/models/sys.rb', line 45

def initialize(sunrise = nil,
               sunset = nil,
               type = nil,
               id = nil,
               message = nil,
               country = nil)
  @type = type
  @id = id
  @message = message
  @country = country
  @sunrise = sunrise
  @sunset = sunset
end

Instance Attribute Details

#countryString

This field contains the country code

Returns:



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

def country
  @country
end

#idInteger

This field contains the identifier

Returns:

  • (Integer)


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

def id
  @id
end

#messageFloat

This field contains the information message

Returns:

  • (Float)


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

def message
  @message
end

#sunriseLong

This field contains the information of sunrise in given city

Returns:

  • (Long)


27
28
29
# File 'lib/weather_api_assignment/models/sys.rb', line 27

def sunrise
  @sunrise
end

#sunsetLong

This field contains the information of sunset in given city

Returns:

  • (Long)


31
32
33
# File 'lib/weather_api_assignment/models/sys.rb', line 31

def sunset
  @sunset
end

#typeInteger

This field contains the type of information

Returns:

  • (Integer)


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

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/weather_api_assignment/models/sys.rb', line 60

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  sunrise = hash['sunrise']
  sunset = hash['sunset']
  type = hash['type']
  id = hash['id']
  message = hash['message']
  country = hash['country']

  # Create object from extracted values.
  Sys.new(sunrise,
          sunset,
          type,
          id,
          message,
          country)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['type'] = 'type'
  @_hash['id'] = 'id'
  @_hash['message'] = 'message'
  @_hash['country'] = 'country'
  @_hash['sunrise'] = 'sunrise'
  @_hash['sunset'] = 'sunset'
  @_hash
end