Module: StructureMapper::Hash::ClassMethods
- Defined in:
- lib/structure_mapper.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
126 127 128 |
# File 'lib/structure_mapper.rb', line 126 def attributes @attributes end |
Instance Method Details
#attribute(options) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/structure_mapper.rb', line 128 def attribute name,type=.first attr_accessor name @attributes=(@attributes || {}) @attributes[name]=type end |
#from_structure(data) ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/structure_mapper.rb', line 135 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 |