class KakaxiParse::Climate

Public Class Methods

new( id: nil, updated_at: nil, created_at: nil, solar_radiation: nil, recorded_at: nil, rain_amount: nil, rainfall: nil, humidity: nil, temperature: nil, weather: nil, device_id: nil, power_feeding: nil, interpolation: nil ) click to toggle source
Calls superclass method KakaxiParse::BaseModel::new
# File lib/kakaxi_parse/climate.rb, line 7
def initialize(
      id: nil,
      updated_at: nil,
      created_at: nil,
      solar_radiation: nil,
      recorded_at: nil,
      rain_amount: nil,
      rainfall: nil,
      humidity: nil,
      temperature: nil,
      weather: nil,
      device_id: nil,
      power_feeding: nil,
      interpolation: nil
    )
  @solar_radiation = solar_radiation
  @recorded_at = DateTime.strptime(recorded_at, '%Y-%m-%dT%H:%M:%S.%LZ')
  @rain_amount = rain_amount
  @humidity = humidity
  @temperature = temperature
  @weather = weather
  @device_id = device_id
  @power_feeding = power_feeding
  @interpolation = interpolation
  super(id, nil, updated_at, created_at)
end
where(hash, limit: DEFUALT_LIMIT) click to toggle source
Calls superclass method KakaxiParse::BaseModel::where
# File lib/kakaxi_parse/climate.rb, line 34
def self.where(hash, limit: DEFUALT_LIMIT)
  to_objects(super(self, hash, limit, @@belongs_to)) if valid_key?(hash)
end

Private Class Methods

to_objects(climates) click to toggle source
# File lib/kakaxi_parse/climate.rb, line 39
def self.to_objects(climates)
  climates.map do |climate|
    new(
      id: climate['objectId'],
      updated_at: climate['updatedAt'],
      created_at: climate['createdAt'],
      solar_radiation: climate['solarRadiation'],
      recorded_at: climate['recordedAt']['iso'],
      rain_amount: climate['rainAmount'],
      rainfall: climate['rainfall'],
      humidity: climate['humidity'],
      temperature: climate['temperature'],
      weather: climate['weather'],
      device_id: climate['device']['objectId'],
      power_feeding: climate['powerFeeding'],
      interpolation: climate['interpolation']
      )
  end
end
valid_key?(hash) click to toggle source
# File lib/kakaxi_parse/climate.rb, line 59
def self.valid_key?(hash)
  hash.keys.all? { |key| %i(id updated_at created_at solar_radiation recorded_at rain_amount rainfall humidity temperature weather device_id power_feeding interpolation).include? key }
end