Class: RBase::Columns::FloatColumn
- Inherits:
-
Column
- Object
- Column
- RBase::Columns::FloatColumn
show all
- Defined in:
- lib/rbase/columns.rb
Instance Attribute Summary
Attributes inherited from Column
#name, #offset, #size
Instance Method Summary
collapse
Methods inherited from Column
#attach_to, column_for, column_type, #type, type
Constructor Details
#initialize(name, options = {}) ⇒ FloatColumn
Returns a new instance of FloatColumn.
229
230
231
|
# File 'lib/rbase/columns.rb', line 229
def initialize(name, options = {})
super name, options.merge(:size => 20)
end
|
Instance Method Details
#decimal ⇒ Object
233
234
235
|
# File 'lib/rbase/columns.rb', line 233
def decimal
(@decimal && @decimal <= 15) ? @decimal : 2
end
|
#inspect ⇒ Object
245
246
247
|
# File 'lib/rbase/columns.rb', line 245
def inspect
"#{name}(float)"
end
|
#pack(value) ⇒ Object
237
238
239
|
# File 'lib/rbase/columns.rb', line 237
def pack(value)
[format("%-#{size-decimal-1}.#{decimal}f", value || 0.0)].pack("A#{size}")
end
|
#unpack(data) ⇒ Object
241
242
243
|
# File 'lib/rbase/columns.rb', line 241
def unpack(data)
data.rstrip.to_f
end
|