Class: MsPivot::Table
- Inherits:
-
Object
- Object
- MsPivot::Table
- Defined in:
- lib/ms_pivot/table.rb
Overview
The table to pivot
Instance Attribute Summary collapse
-
#column_headers ⇒ Object
Returns the value of attribute column_headers.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(orig_array, row_index, col_index, *measures) ⇒ Table
constructor
A new instance of Table.
- #inspect ⇒ Object
- #row_headers ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(orig_array, row_index, col_index, *measures) ⇒ Table
Returns a new instance of Table.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ms_pivot/table.rb', line 10 def initialize(orig_array, row_index, col_index, *measures) @data = {} @column_headers = nil @row_index = row_index @col_index = col_index @measures = measures @orig_array = orig_array @orig_array compile(@orig_array) end |
Instance Attribute Details
#column_headers ⇒ Object
Returns the value of attribute column_headers.
8 9 10 |
# File 'lib/ms_pivot/table.rb', line 8 def column_headers @column_headers end |
Instance Method Details
#each ⇒ Object
27 28 29 30 31 |
# File 'lib/ms_pivot/table.rb', line 27 def each @data.each do |row_header, columns| yield row_header, columns end end |
#inspect ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ms_pivot/table.rb', line 45 def inspect result = "\t" self.column_headers.each do |header| result << "\t#{header}" end result << "\n" self.each do |row_header, columns| result << row_header.to_s columns.each do |col_header, values| result << "\t" + (values.empty? ? "-" : "#{values.join(",")}") end result << "\n" end result end |
#row_headers ⇒ Object
33 34 35 |
# File 'lib/ms_pivot/table.rb', line 33 def row_headers @data.keys end |
#to_a ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/ms_pivot/table.rb', line 37 def to_a result = [] self.each do |row_header, columns| result << Array(row_header) + columns.to_a end result end |