Class: ActiveRecord::Result::IndexedRow

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(column_indexes, row) ⇒ IndexedRow

Returns a new instance of IndexedRow.



45
46
47
48
# File 'lib/active_record/result.rb', line 45

def initialize(column_indexes, row)
  @column_indexes = column_indexes
  @row = row
end

Instance Method Details

#==(other) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/active_record/result.rb', line 63

def ==(other)
  if other.is_a?(Hash)
    to_hash == other
  else
    super
  end
end

#[](column) ⇒ Object



85
86
87
88
89
# File 'lib/active_record/result.rb', line 85

def [](column)
  if index = @column_indexes[column]
    @row[index]
  end
end

#each_key(&block) ⇒ Object



55
56
57
# File 'lib/active_record/result.rb', line 55

def each_key(&block)
  @column_indexes.each_key(&block)
end

#fetch(column) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/active_record/result.rb', line 75

def fetch(column)
  if index = @column_indexes[column]
    @row[index]
  elsif block_given?
    yield
  else
    raise KeyError, "key not found: #{column.inspect}"
  end
end

#key?(column) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/active_record/result.rb', line 71

def key?(column)
  @column_indexes.key?(column)
end

#keysObject



59
60
61
# File 'lib/active_record/result.rb', line 59

def keys
  @column_indexes.keys
end

#sizeObject Also known as: length



50
51
52
# File 'lib/active_record/result.rb', line 50

def size
  @column_indexes.size
end

#to_hObject Also known as: to_hash



91
92
93
# File 'lib/active_record/result.rb', line 91

def to_h
  @column_indexes.transform_values { |index| @row[index] }
end