Class: Tarantool::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/tarantool/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Field

Returns a new instance of Field.



4
5
6
# File 'lib/tarantool/response.rb', line 4

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/tarantool/response.rb', line 3

def data
  @data
end

Instance Method Details

#to_iObject



8
9
10
11
12
13
14
15
16
# File 'lib/tarantool/response.rb', line 8

def to_i
  if data.bytesize == 4
    data.unpack('L')[0]
  elsif data.bytesize == 8
    data.unpack('Q')[0]
  else
    raise ValueError.new("Unable to cast field to int: length must be 4 or 8 bytes, field length is #{data.size}")
  end
end

#to_sObject



18
19
20
# File 'lib/tarantool/response.rb', line 18

def to_s
  data.dup.force_encoding('utf-8')
end