Class: FixedLayoutMapper::Mapper::SimpleMapper

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, len, converter = nil) ⇒ SimpleMapper

Returns a new instance of SimpleMapper.



25
26
27
28
# File 'lib/fixed-layout-mapper.rb', line 25

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

Instance Method Details

#lengthObject



30
31
32
# File 'lib/fixed-layout-mapper.rb', line 30

def length
  @len
end

#map(bytes) ⇒ Object



34
35
36
37
38
# File 'lib/fixed-layout-mapper.rb', line 34

def map(bytes)
  value = bytes.take(@len).pack("C*").force_encoding(layout_mapper.encoding)
  #value = converter.(value) if converter
  [convert(value), bytes.drop(@len)]
end