Class: Datasets::Table::Record
- Inherits:
-
Object
- Object
- Datasets::Table::Record
- Includes:
- Enumerable
- Defined in:
- lib/datasets/table.rb
Instance Method Summary collapse
- #[](column_name_or_column_index) ⇒ Object
- #each ⇒ Object
-
#initialize(table, index) ⇒ Record
constructor
A new instance of Record.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(table, index) ⇒ Record
Returns a new instance of Record.
8 9 10 11 |
# File 'lib/datasets/table.rb', line 8 def initialize(table, index) @table = table @index = index end |
Instance Method Details
#[](column_name_or_column_index) ⇒ Object
13 14 15 |
# File 'lib/datasets/table.rb', line 13 def [](column_name_or_column_index) @table[column_name_or_column_index][@index] end |
#each ⇒ Object
17 18 19 20 21 22 |
# File 'lib/datasets/table.rb', line 17 def each return to_enum(__method__) unless block_given? @table.each_column.each do |column_name, column_values| yield(column_name, column_values[@index]) end end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/datasets/table.rb', line 38 def inspect "#<#{self.class.name} #{@table.dataset..name}[#{@index}] #{to_h.inspect}>" end |
#to_h ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/datasets/table.rb', line 30 def to_h hash = {} each do |column_name, column_value| hash[column_name] = column_value end hash end |
#values ⇒ Object
24 25 26 27 28 |
# File 'lib/datasets/table.rb', line 24 def values @table.each_column.collect do |_column_name, column_values| column_values[@index] end end |