Class: WeatherApiAssignment::Main

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

Overview

This model contains the digital values of weather.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(temp = nil, pressure = nil, humidity = nil, temp_min = nil, temp_max = nil, feels_like = nil, sea_level = nil, grnd_level = nil) ⇒ Main

Returns a new instance of Main.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/weather_api_assignment/models/main.rb', line 55

def initialize(temp = nil,
               pressure = nil,
               humidity = nil,
               temp_min = nil,
               temp_max = nil,
               feels_like = nil,
               sea_level = nil,
               grnd_level = nil)
  @temp = temp
  @feels_like = feels_like
  @pressure = pressure
  @humidity = humidity
  @temp_min = temp_min
  @temp_max = temp_max
  @sea_level = sea_level
  @grnd_level = grnd_level
end

Instance Attribute Details

#feels_likeFloat

This field contains the feels like attribute of temperature

Returns:

  • (Float)


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

def feels_like
  @feels_like
end

#grnd_levelFloat

This field contains the information height with respect to ground level

Returns:

  • (Float)


39
40
41
# File 'lib/weather_api_assignment/models/main.rb', line 39

def grnd_level
  @grnd_level
end

#humidityFloat

This field contains the humidity

Returns:

  • (Float)


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

def humidity
  @humidity
end

#pressureFloat

This field contains the pressure

Returns:

  • (Float)


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

def pressure
  @pressure
end

#sea_levelFloat

This field contains the information height with respect to sea level

Returns:

  • (Float)


35
36
37
# File 'lib/weather_api_assignment/models/main.rb', line 35

def sea_level
  @sea_level
end

#tempFloat

This field contains the current temperature

Returns:

  • (Float)


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

def temp
  @temp
end

#temp_maxFloat

This field contains the maximum temperature

Returns:

  • (Float)


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

def temp_max
  @temp_max
end

#temp_minFloat

This field contains the minimum temperature

Returns:

  • (Float)


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

def temp_min
  @temp_min
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/weather_api_assignment/models/main.rb', line 74

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  temp = hash['temp']
  pressure = hash['pressure']
  humidity = hash['humidity']
  temp_min = hash['temp_min']
  temp_max = hash['temp_max']
  feels_like = hash['feels_like']
  sea_level = hash['sea_level']
  grnd_level = hash['grnd_level']

  # Create object from extracted values.
  Main.new(temp,
           pressure,
           humidity,
           temp_min,
           temp_max,
           feels_like,
           sea_level,
           grnd_level)
end

.namesObject

A mapping from model property names to API property names.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/weather_api_assignment/models/main.rb', line 42

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['temp'] = 'temp'
  @_hash['feels_like'] = 'feels_like'
  @_hash['pressure'] = 'pressure'
  @_hash['humidity'] = 'humidity'
  @_hash['temp_min'] = 'temp_min'
  @_hash['temp_max'] = 'temp_max'
  @_hash['sea_level'] = 'sea_level'
  @_hash['grnd_level'] = 'grnd_level'
  @_hash
end