Class: Tarantool::Field
- Inherits:
-
Object
- Object
- Tarantool::Field
- Defined in:
- lib/tarantool/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(data) ⇒ Field
constructor
A new instance of Field.
- #to_i ⇒ Object
- #to_s ⇒ Object
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
#data ⇒ Object (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_i ⇒ Object
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_s ⇒ Object
18 19 20 |
# File 'lib/tarantool/response.rb', line 18 def to_s data.dup.force_encoding('utf-8') end |