Method: Airthings::Location#initialize

Defined in:
lib/airthings/models/location.rb

#initialize(attributes = {}) ⇒ Location

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/airthings/models/location.rb', line 50

def initialize(attributes = {})
  unless attributes.is_a?(Hash)
    raise ArgumentError, "The input argument (attributes) must be a hash in `Airthings::Location` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) do |(k, v), h|
    unless self.class.attribute_map.key?(k.to_sym)
      raise ArgumentError, "`#{k}` is not a valid attribute in `Airthings::Location`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end

    h[k.to_sym] = v
  end

  self.id = attributes[:id] if attributes.key?(:id)

  self.name = attributes[:name] if attributes.key?(:name)

  if attributes.key?(:labels) && (value = attributes[:labels]).is_a?(Hash)
    self.labels = value
  end
end