Module: Arrow::ColumnContainable

Included in:
RecordBatch, Table
Defined in:
lib/arrow/column-containable.rb

Instance Method Summary collapse

Instance Method Details

#columnsObject



20
21
22
23
24
# File 'lib/arrow/column-containable.rb', line 20

def columns
  @columns ||= schema.n_fields.times.collect do |i|
    Column.new(self, i)
  end
end

#each_column(&block) ⇒ Object



26
27
28
# File 'lib/arrow/column-containable.rb', line 26

def each_column(&block)
  columns.each(&block)
end

#find_column(name_or_index) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/arrow/column-containable.rb', line 30

def find_column(name_or_index)
  case name_or_index
  when String, Symbol
    name = name_or_index.to_s
    index = schema.get_field_index(name)
    return nil if index == -1
    Column.new(self, index)
  when Integer
    index = name_or_index
    index += n_columns if index < 0
    return nil if index < 0 or index >= n_columns
    Column.new(self, index)
  else
    message = "column name or index must be String, Symbol or Integer"
    raise ArgumentError, message
  end
end