Class: Codec::Numebc

Inherits:
Base
  • Object
show all
Defined in:
lib/codec/fix.rb

Instance Attribute Summary

Attributes inherited from Base

#id

Instance Method Summary collapse

Methods inherited from Base

#add_sub_codec, #decode, #decode_with_length, #encode_with_length, #eval_length, #get_length, #get_sub_codecs, #initialize

Constructor Details

This class inherits a constructor from Codec::Base

Instance Method Details

#build_field(buf, length) ⇒ Object



63
64
65
66
67
# File 'lib/codec/fix.rb', line 63

def build_field(buf,length)
  f = Field.new(@id)
  f.set_value(EightBitsEncoding::EBCDIC_2_UTF8(buf[0,length]).to_i)
  return f
end

#encode(field) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/codec/fix.rb', line 69

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