Class: WeatherApiAssignment::Main
- Defined in:
- lib/weather_api_assignment/models/main.rb
Overview
This model contains the digital values of weather.
Instance Attribute Summary collapse
-
#feels_like ⇒ Float
This field contains the feels like attribute of temperature.
-
#grnd_level ⇒ Float
This field contains the information height with respect to ground level.
-
#humidity ⇒ Float
This field contains the humidity.
-
#pressure ⇒ Float
This field contains the pressure.
-
#sea_level ⇒ Float
This field contains the information height with respect to sea level.
-
#temp ⇒ Float
This field contains the current temperature.
-
#temp_max ⇒ Float
This field contains the maximum temperature.
-
#temp_min ⇒ Float
This field contains the minimum temperature.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
Instance Method Summary collapse
-
#initialize(temp = nil, pressure = nil, humidity = nil, temp_min = nil, temp_max = nil, feels_like = nil, sea_level = nil, grnd_level = nil) ⇒ Main
constructor
A new instance of Main.
Methods inherited from BaseModel
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_like ⇒ Float
This field contains the feels like attribute of temperature
15 16 17 |
# File 'lib/weather_api_assignment/models/main.rb', line 15 def feels_like @feels_like end |
#grnd_level ⇒ Float
This field contains the information height with respect to ground level
39 40 41 |
# File 'lib/weather_api_assignment/models/main.rb', line 39 def grnd_level @grnd_level end |
#humidity ⇒ Float
This field contains the humidity
23 24 25 |
# File 'lib/weather_api_assignment/models/main.rb', line 23 def humidity @humidity end |
#pressure ⇒ Float
This field contains the pressure
19 20 21 |
# File 'lib/weather_api_assignment/models/main.rb', line 19 def pressure @pressure end |
#sea_level ⇒ Float
This field contains the information height with respect to sea level
35 36 37 |
# File 'lib/weather_api_assignment/models/main.rb', line 35 def sea_level @sea_level end |
#temp ⇒ Float
This field contains the current temperature
11 12 13 |
# File 'lib/weather_api_assignment/models/main.rb', line 11 def temp @temp end |
#temp_max ⇒ Float
This field contains the maximum temperature
31 32 33 |
# File 'lib/weather_api_assignment/models/main.rb', line 31 def temp_max @temp_max end |
#temp_min ⇒ Float
This field contains the minimum temperature
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 |
.names ⇒ Object
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 |