Class: Riak::Client::BeefcakeProtobuffsBackend::TsCellCodec
- Defined in:
- lib/riak/client/beefcake/ts_cell_codec.rb
Instance Attribute Summary collapse
-
#convert_timestamp ⇒ Object
Returns the value of attribute convert_timestamp.
Instance Method Summary collapse
- #cell_for(measure) ⇒ Object
- #cells_for(measures) ⇒ Object
-
#initialize(convert_timestamp = false) ⇒ TsCellCodec
constructor
A new instance of TsCellCodec.
- #scalar_for(cell) ⇒ Object
- #scalars_for(cells) ⇒ Object
Constructor Details
#initialize(convert_timestamp = false) ⇒ TsCellCodec
Returns a new instance of TsCellCodec.
7 8 9 |
# File 'lib/riak/client/beefcake/ts_cell_codec.rb', line 7 def initialize( = false) @convert_timestamp = end |
Instance Attribute Details
#convert_timestamp ⇒ Object
Returns the value of attribute convert_timestamp.
5 6 7 |
# File 'lib/riak/client/beefcake/ts_cell_codec.rb', line 5 def @convert_timestamp end |
Instance Method Details
#cell_for(measure) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
11 12 13 |
# 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) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/riak/client/beefcake/ts_cell_codec.rb', line 47 def scalar_for(cell) cell.varchar_value || cell.sint64_value || cell.double_value || (cell) || cell.boolean_value # boolean_value is last, so we can get either false, nil, or true end |
#scalars_for(cells) ⇒ Object
15 16 17 |
# File 'lib/riak/client/beefcake/ts_cell_codec.rb', line 15 def scalars_for(cells) cells.map{ |c| scalar_for c } end |