Class: RBase::Columns::NumberColumn
- Inherits:
-
Column
- Object
- Column
- RBase::Columns::NumberColumn
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 = {}) ⇒ NumberColumn
Returns a new instance of NumberColumn.
114
115
116
117
118
119
|
# File 'lib/rbase/columns.rb', line 114
def initialize(name, options = {})
size = options[:size] || 18
size = 18 if size > 18
super name, options.merge(:size => size)
end
|
Instance Method Details
#float? ⇒ Boolean
146
147
148
|
# File 'lib/rbase/columns.rb', line 146
def float?
decimal && decimal != 0
end
|
#inspect ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/rbase/columns.rb', line 138
def inspect
if float?
"#{name}(decimal)"
else
"#{name}(integer)"
end
end
|
#pack(value) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/rbase/columns.rb', line 121
def pack(value)
if value
if float?
[format("%#{size-decimal-1}.#{decimal}f", value)].pack("A#{size}")
else
[format("%#{size}d", value)].pack("A#{size}")
end
else
" "*size
end
end
|
#unpack(data) ⇒ Object
133
134
135
136
|
# File 'lib/rbase/columns.rb', line 133
def unpack(data)
return nil if data.strip == ''
data.rstrip.to_i
end
|