Class: Tarantool::TranslateToHash

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

Overview

note that :_tail should not be in field_names

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#field_namesObject

Returns the value of attribute field_names

Returns:

  • (Object)

    the current value of field_names



167
168
169
# File 'lib/tarantool/response.rb', line 167

def field_names
  @field_names
end

#tail_sizeObject

Returns the value of attribute tail_size

Returns:

  • (Object)

    the current value of tail_size



167
168
169
# File 'lib/tarantool/response.rb', line 167

def tail_size
  @tail_size
end

Instance Method Details

#call(tuple) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/tarantool/response.rb', line 168

def call(tuple)
  i = 0
  hash = {}
  tuple_size = tuple.size
  names = field_names
  while i < tuple_size
    if name = names[i]
      hash[name] = tuple[i]
    else
      tail = tuple.slice(i..-1)
      hash[:_tail] = tail_size == 1 ? tail :
                     tail.each_slice(tail_size).to_a
      break
    end
    i += 1
  end
  hash
end