Class: RBase::Columns::FloatColumn

Inherits:
Column
  • Object
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



231
232
233
# File 'lib/rbase/columns.rb', line 231

def initialize(name, options = {})
  super name, options.merge(:size => 20)
end

Instance Method Details

#decimalObject



235
236
237
# File 'lib/rbase/columns.rb', line 235

def decimal
  (@decimal && @decimal <= 15) ? @decimal : 2
end

#inspectObject



247
248
249
# File 'lib/rbase/columns.rb', line 247

def inspect
  "#{name}(float)"
end

#pack(value) ⇒ Object



239
240
241
# File 'lib/rbase/columns.rb', line 239

def pack(value)
  [format("%-#{size-decimal-1}.#{decimal}f", value || 0.0)].pack("A#{size}")
end

#unpack(data) ⇒ Object



243
244
245
# File 'lib/rbase/columns.rb', line 243

def unpack(data)
  data.rstrip.to_f
end