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.



71
72
73
# File 'lib/structure_mapper.rb', line 71

def attributes
  @attributes
end

Instance Method Details

#attribute(options) ⇒ Object



73
74
75
76
77
78
# File 'lib/structure_mapper.rb', line 73

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

#from_structure(data) ⇒ Object



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

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