Class: Arrow::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/arrow/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record_container, index) ⇒ Record

Returns a new instance of Record.



21
22
23
24
# File 'lib/arrow/record.rb', line 21

def initialize(record_container, index)
  @record_container = record_container
  @index = index
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/arrow/record.rb', line 49

def method_missing(name, *args, &block)
  if args.empty?
    column = @record_container.find_column(name)
    return column[@index] if column
  end
  super
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



20
21
22
# File 'lib/arrow/record.rb', line 20

def index
  @index
end

Instance Method Details

#[](column_name_or_column_index) ⇒ Object



26
27
28
29
30
# File 'lib/arrow/record.rb', line 26

def [](column_name_or_column_index)
  column = @record_container.find_column(column_name_or_column_index)
  return nil if column.nil?
  column[@index]
end

#columnsObject



32
33
34
# File 'lib/arrow/record.rb', line 32

def columns
  @record_container.columns
end

#respond_to_missing?(name, include_private) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/arrow/record.rb', line 44

def respond_to_missing?(name, include_private)
  return true if @record_container.find_column(name)
  super
end

#to_hObject



36
37
38
39
40
41
42
# File 'lib/arrow/record.rb', line 36

def to_h
  attributes = {}
  @record_container.schema.fields.each_with_index do |field, i|
    attributes[field.name] = self[i]
  end
  attributes
end