Class: RBase::Columns::CharacterColumn
- Defined in:
- lib/rbase/columns.rb
Instance Attribute Summary
Attributes inherited from Column
#decimal, #name, #offset, #size
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ CharacterColumn
constructor
A new instance of CharacterColumn.
- #inspect ⇒ Object
- #pack(value) ⇒ Object
- #unpack(data) ⇒ Object
Methods inherited from Column
#attach_to, column_for, column_type, #type, type
Constructor Details
#initialize(name, options = {}) ⇒ CharacterColumn
Returns a new instance of CharacterColumn.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rbase/columns.rb', line 78 def initialize(name, = {}) if [:size] && [:decimal] size = [:decimal]*256 + [:size] else size = [:size] || 254 end super name, .merge(:size => size) if [:encoding] @unpack_converter = Iconv.new('utf-8', [:encoding]) @pack_converter = Iconv.new([:encoding], 'utf-8') end end |
Instance Method Details
#inspect ⇒ Object
105 106 107 |
# File 'lib/rbase/columns.rb', line 105 def inspect "#{name}(string #{size})" end |
#pack(value) ⇒ Object
93 94 95 96 97 |
# File 'lib/rbase/columns.rb', line 93 def pack(value) value = value.to_s value = @pack_converter.iconv(value) if @pack_converter [value].pack("A#{size}") end |
#unpack(data) ⇒ Object
99 100 101 102 103 |
# File 'lib/rbase/columns.rb', line 99 def unpack(data) value = data.rstrip value = @unpack_converter.iconv(value) if @unpack_converter value end |