Module: Dhl::Bcs::V2::Buildable::ClassMethods

Defined in:
lib/dhl/bcs/v2/buildable.rb

Instance Method Summary collapse

Instance Method Details

#build(**attributes) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dhl/bcs/v2/buildable.rb', line 9

def build(**attributes)
  attrib = attributes[underscore(name.split('::').last).to_sym]
  if attrib.is_a?(self)
    attrib
  elsif attrib.nil?
    klass_attributes = {}
    self::PROPERTIES.each do |prop|
      value = attributes.delete(prop)
      klass_attributes[prop] = value if value
    end
    new(**klass_attributes)
  elsif attrib.is_a?(Hash)
    new(**attrib)
  end
end