Class: MsPivot::Row
- Inherits:
-
Object
- Object
- MsPivot::Row
- Defined in:
- lib/ms_pivot/row.rb
Overview
The table to pivot
Instance Attribute Summary collapse
-
#column_headers ⇒ Object
Returns the value of attribute column_headers.
Instance Method Summary collapse
- #[](col_header) ⇒ Object
- #[]=(col_header, *values) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ Row
constructor
A new instance of Row.
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ Row
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_headers ⇒ Object
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 |
#each ⇒ Object
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_a ⇒ Object
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 |