Class: MassiveRecord::Wrapper::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/massive_record/wrapper/cell.rb

Constant Summary collapse

SUPPORTED_TYPES =
[NilClass, String, Fixnum, Bignum]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Cell

Returns a new instance of Cell.



35
36
37
38
# File 'lib/massive_record/wrapper/cell.rb', line 35

def initialize(opts = {})
  self.value = opts[:value]
  self.created_at = opts[:created_at]
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



7
8
9
# File 'lib/massive_record/wrapper/cell.rb', line 7

def created_at
  @created_at
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/massive_record/wrapper/cell.rb', line 6

def value
  @value
end

Class Method Details

.hex_string_to_integer(string) ⇒ Object

Unpacks an string as a 64-bit signed integer, native endian (int64_t) Reverse it before unpack as the byte order in hbase are reversed



22
23
24
# File 'lib/massive_record/wrapper/cell.rb', line 22

def self.hex_string_to_integer(string)
  string.reverse.unpack("q*").first
end

.integer_to_hex_string(int) ⇒ Object



14
15
16
# File 'lib/massive_record/wrapper/cell.rb', line 14

def self.integer_to_hex_string(int)
  [int].pack('q').reverse
end

.populate_from_tcell(tcell) ⇒ Object



27
28
29
30
31
32
# File 'lib/massive_record/wrapper/cell.rb', line 27

def self.populate_from_tcell(tcell)
  new({
    :value => tcell.value,
    :created_at => Time.at(tcell.timestamp / 1000, (tcell.timestamp % 1000) * 1000)
  })
end

Instance Method Details

#value_to_thriftObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/massive_record/wrapper/cell.rb', line 46

def value_to_thrift
  case value
  when String
    value.force_encoding(Encoding::BINARY)
  when Fixnum, Bignum
    self.class.integer_to_hex_string(value)
  when NilClass
    value
  end
end