Module: StructureMapper::Hash::ClassMethods

Defined in:
lib/structure_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



117
118
119
# File 'lib/structure_mapper.rb', line 117

def attributes
  @attributes
end

Instance Method Details

#attribute(options) ⇒ Object



119
120
121
122
123
124
# File 'lib/structure_mapper.rb', line 119

def attribute options
  name,type=options.first
  attr_accessor name
  @attributes=(@attributes || {})
  @attributes[name]=type
end

#from_structure(data) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/structure_mapper.rb', line 126

def from_structure data
  return nil unless data
  result=self.new
  @attributes.each do |name, type|
    result.public_send ("%s=" % name), type.from_structure(data[name.to_s])
  end
  result
end