class Riak::Client::BeefcakeProtobuffsBackend::TsCellCodec
Attributes
convert_timestamp[RW]
Public Class Methods
new(convert_timestamp = false)
click to toggle source
# File lib/riak/client/beefcake/ts_cell_codec.rb, line 7 def initialize(convert_timestamp = false) @convert_timestamp = convert_timestamp end
Public Instance Methods
cell_for(measure)
click to toggle source
# File lib/riak/client/beefcake/ts_cell_codec.rb, line 19 def cell_for(measure) TsCell.new case measure when String { varchar_value: measure } when Fixnum { sint64_value: measure } when Bignum { sint64_value: check_bignum_range(measure) } when Float { double_value: measure } when BigDecimal { double_value: measure.to_f } when Rational fail Riak::TimeSeriesError::SerializeRationalNumberError when Complex fail Riak::TimeSeriesError::SerializeComplexNumberError when Time seconds = measure.to_f milliseconds = seconds * 1000 truncated_ms = milliseconds.to_i { timestamp_value: truncated_ms } when TrueClass, FalseClass { boolean_value: measure } when nil { } end end
cells_for(measures)
click to toggle source
# File lib/riak/client/beefcake/ts_cell_codec.rb, line 11 def cells_for(measures) measures.map{ |m| cell_for m } end
scalar_for(cell)
click to toggle source
# File lib/riak/client/beefcake/ts_cell_codec.rb, line 47 def scalar_for(cell) cell.varchar_value || cell.sint64_value || cell.double_value || timestamp(cell) || cell.boolean_value # boolean_value is last, so we can get either false, nil, or true end
scalars_for(cells)
click to toggle source
# File lib/riak/client/beefcake/ts_cell_codec.rb, line 15 def scalars_for(cells) cells.map{ |c| scalar_for c } end
Private Instance Methods
check_bignum_range(bignum)
click to toggle source
# File lib/riak/client/beefcake/ts_cell_codec.rb, line 56 def check_bignum_range(bignum) if (bignum > -0x8000000000000000) && (bignum < 0x7FFFFFFFFFFFFFFF) return bignum end fail Riak::TimeSeriesError::SerializeBigIntegerError, bignum end
timestamp(cell)
click to toggle source
# File lib/riak/client/beefcake/ts_cell_codec.rb, line 64 def timestamp(cell) return false unless cell.timestamp_value.is_a? Integer return cell.timestamp_value unless @convert_timestamp tsv = cell.timestamp_value secs = tsv / 1000 msec = tsv % 1000 Time.at(secs, msec * 1000) end