Class: Turso::Row

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/turso/row.rb

Instance Method Summary collapse

Constructor Details

#initialize(values, column_names) ⇒ Row

Returns a new instance of Row.



7
8
9
10
# File 'lib/turso/row.rb', line 7

def initialize(values, column_names)
  @values = values
  @column_names = column_names
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/turso/row.rb', line 16

def [](key)
  case key
  when Integer
    @values[key]
  when String, Symbol
    @values[column_index(key.to_s)]
  else
    raise ArgumentError, "invalid key type: #{key.class}"
  end
end

#each(&block) ⇒ Object



27
28
29
# File 'lib/turso/row.rb', line 27

def each(&block)
  @values.each(&block)
end

#lengthObject Also known as: size



31
32
33
# File 'lib/turso/row.rb', line 31

def length
  @values.length
end

#to_aObject



12
13
14
# File 'lib/turso/row.rb', line 12

def to_a
  @values.dup
end