Class: Reportability::Table
- Inherits:
-
Object
- Object
- Reportability::Table
- Defined in:
- lib/reportability/pivot.rb
Instance Attribute Summary collapse
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize(args) ⇒ Table
constructor
A new instance of Table.
- #inspect ⇒ Object
- #max_column_length(col) ⇒ Object
Constructor Details
#initialize(args) ⇒ Table
4 5 6 |
# File 'lib/reportability/pivot.rb', line 4 def initialize(args) @cols, @rows = args[:cols], args[:rows] end |
Instance Attribute Details
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
3 4 5 |
# File 'lib/reportability/pivot.rb', line 3 def cols @cols end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
3 4 5 |
# File 'lib/reportability/pivot.rb', line 3 def rows @rows end |
Instance Method Details
#inspect ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/reportability/pivot.rb', line 8 def inspect lengths = cols.map { |col| max_column_length(col) } rows.map do |row| "|".tap do |s| row.each_index { |i| s << (" %-#{lengths[i]}s |" % row[i].to_s)} end end.join("\n") end |
#max_column_length(col) ⇒ Object
17 18 19 20 |
# File 'lib/reportability/pivot.rb', line 17 def max_column_length(col) idx = cols.index(col) ([col.to_s] + rows).map { |row| row[idx].to_s.length }.max end |