Module: StructureMapper::Array::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.



80
81
82
# File 'lib/structure_mapper.rb', line 80

def attributes
  @attributes
end

Instance Method Details

#attribute(options) ⇒ Object



82
83
84
85
86
87
# File 'lib/structure_mapper.rb', line 82

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

#from_structure(data) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/structure_mapper.rb', line 89

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