Class: Codec::Numebc

Inherits:
Fix show all
Defined in:
lib/codec/fix.rb

Instance Method Summary collapse

Methods inherited from Fix

#check_length, #decode, #initialize

Methods inherited from Base

#add_sub_codec, #decode, #get_sub_codecs

Constructor Details

This class inherits a constructor from Codec::Fix

Instance Method Details

#build_field(buf, f, length) ⇒ Object



89
90
91
# File 'lib/codec/fix.rb', line 89

def build_field(buf,f,length)
  f.set_value(EightBitsEncoding::EBCDIC_2_UTF8(buf.slice!(0...length)).to_i)
end

#encode(buf, field) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/codec/fix.rb', line 93

def encode(buf, field)
  out = field.get_value.to_s
  if @length > 0
    out = out.rjust(@length,"0")
    raise TooLongDataException if out.length > @length
  end
  buf << EightBitsEncoding::UTF8_2_EBCDIC(out)
  return out.length      
end