Class: Riak::Client::BeefcakeProtobuffsBackend::TsCellCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/riak/client/beefcake/ts_cell_codec.rb

Instance Method Summary collapse

Instance Method Details

#cell_for(measure) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/riak/client/beefcake/ts_cell_codec.rb', line 13

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



5
6
7
# File 'lib/riak/client/beefcake/ts_cell_codec.rb', line 5

def cells_for(measures)
  measures.map{ |m| cell_for m }
end

#scalar_for(cell) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/riak/client/beefcake/ts_cell_codec.rb', line 41

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) ⇒ Object



9
10
11
# File 'lib/riak/client/beefcake/ts_cell_codec.rb', line 9

def scalars_for(cells)
  cells.map{ |c| scalar_for c }
end