Class: MsPivot::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/ms_pivot/row.rb

Overview

The table to pivot

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRow

Returns a new instance of Row.



10
11
12
# File 'lib/ms_pivot/row.rb', line 10

def initialize
  @values = Hash.new { |h,k| h[k] = [] }
end

Instance Attribute Details

#column_headersObject

Returns the value of attribute column_headers.



8
9
10
# File 'lib/ms_pivot/row.rb', line 8

def column_headers
  @column_headers
end

Instance Method Details

#[](col_header) ⇒ Object



24
25
26
# File 'lib/ms_pivot/row.rb', line 24

def [](col_header)
  @values[col_header]
end

#[]=(col_header, *values) ⇒ Object



20
21
22
# File 'lib/ms_pivot/row.rb', line 20

def []=(col_header, *values)
  @values[col_header] = values
end

#eachObject



14
15
16
17
18
# File 'lib/ms_pivot/row.rb', line 14

def each
  @column_headers.each do |col_header|
    yield col_header, @values[col_header]
  end
end

#to_aObject



28
29
30
31
32
33
34
# File 'lib/ms_pivot/row.rb', line 28

def to_a
  result = []
  self.each do |col_header, values|
    result << values
  end
  result
end