Class: FixedLayoutMapper::Mapper::ArrayMapper

Inherits:
ColumnMapper
  • Object
show all
Defined in:
lib/fixed-layout-mapper.rb

Instance Attribute Summary

Attributes inherited from ColumnMapper

#converter, #layout_mapper

Instance Method Summary collapse

Methods inherited from ColumnMapper

#convert

Constructor Details

#initialize(layout_mapper, mappers, converter = nil) ⇒ ArrayMapper

Returns a new instance of ArrayMapper.



58
59
60
61
# File 'lib/fixed-layout-mapper.rb', line 58

def initialize(layout_mapper, mappers, converter = nil)
  super layout_mapper, converter
  @mappers = mappers
end

Instance Method Details

#lengthObject



73
74
75
76
77
# File 'lib/fixed-layout-mapper.rb', line 73

def length
  @mappers.inject(0) do |acc, m|
    acc += m.length
  end
end

#map(bytes) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/fixed-layout-mapper.rb', line 63

def map(bytes)
  ret = []
  rest = @mappers.inject(bytes) do |acc, mapper|
    value, acc = mapper.map(acc)
    ret << value
    acc
  end
  [convert(ret), rest]
end