Class: RBase::Columns::CharacterColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/rbase/columns.rb

Instance Attribute Summary

Attributes inherited from Column

#decimal, #name, #offset, #size

Instance Method Summary collapse

Methods inherited from Column

#attach_to, column_for, column_type, #type, type

Constructor Details

#initialize(name, options = {}) ⇒ CharacterColumn

Returns a new instance of CharacterColumn.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rbase/columns.rb', line 76

def initialize(name, options = {})
  if options[:size] && options[:decimal]
    size = options[:decimal]*256 + options[:size] 
  else
    size = options[:size] || 254
  end
  
  super name, options.merge(:size => size)

  if options[:encoding]
    @unpack_converter = Encoder.new(options[:encoding], 'utf-8')
    @pack_converter = Encoder.new('utf-8', options[:encoding])
  end
end

Instance Method Details

#inspectObject



103
104
105
# File 'lib/rbase/columns.rb', line 103

def inspect
  "#{name}(string #{size})"
end

#pack(value) ⇒ Object



91
92
93
94
95
# File 'lib/rbase/columns.rb', line 91

def pack(value)
 value = value.to_s
  value = @pack_converter.en(value) if @pack_converter
  [value].pack("A#{size}")
end

#unpack(data) ⇒ Object



97
98
99
100
101
# File 'lib/rbase/columns.rb', line 97

def unpack(data)
  value = data.rstrip
  value = @unpack_converter.en(value) if @unpack_converter
  value
end