Class: BigMarkerClient::Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/big_marker_client/models/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Base

Returns a new instance of Base.



4
5
6
7
8
9
# File 'lib/big_marker_client/models/base.rb', line 4

def initialize(hash)
  return unless hash.is_a?(Hash)

  known_attributes = self.class.instance_methods
  hash.each { |k, v| known_attributes.include?(k.to_sym) ? send(:"#{k}=", v) : warn("missing property: #{k}") }
end

Instance Method Details

#to_hObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/big_marker_client/models/base.rb', line 11

def to_h
  instance_variables.each_with_object({}) do |var, hash|
    value = instance_variable_get(var)
    hash[key(var)] = if value.is_a?(Array) && !value.empty? && value.first.is_a?(::BigMarkerClient::Models::Base)
                       value.map(&:to_h)
                     elsif value.is_a?(::BigMarkerClient::Models::Base)
                       value.to_h
                     else
                       value
                     end
  end
end