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(container, index) ⇒ Record

Returns a new instance of Record.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



52
53
54
55
56
57
58
# File 'lib/arrow/record.rb', line 52

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

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



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

def container
  @container
end

#indexObject

Returns the value of attribute index.



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

def index
  @index
end

Instance Method Details

#[](column_name_or_column_index) ⇒ Object



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

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

#respond_to_missing?(name, include_private) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/arrow/record.rb', line 47

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

#to_aObject



33
34
35
36
37
# File 'lib/arrow/record.rb', line 33

def to_a
  @container.columns.collect do |column|
    column[@index]
  end
end

#to_hObject



39
40
41
42
43
44
45
# File 'lib/arrow/record.rb', line 39

def to_h
  attributes = {}
  @container.columns.each do |column|
    attributes[column.name] = column[@index]
  end
  attributes
end