Class: SimpleTables::Table
- Inherits:
-
Object
- Object
- SimpleTables::Table
- Defined in:
- lib/simple_tables/table.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(data, col_names) ⇒ Table
constructor
A new instance of Table.
- #pivot(rows_col, cols_col, &block) ⇒ Object
- #where(conditions) ⇒ Object
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/simple_tables/table.rb', line 3 def data @data end |
Instance Method Details
#pivot(rows_col, cols_col, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/simple_tables/table.rb', line 13 def pivot(rows_col,cols_col,&block) result=@data.group_by{|r| [r[cols_col],r[rows_col]]} if block_given? return PivotTable[result.map{|k,v| [k,block.call(v)] }] end PivotTable[result.map{|k,v| [k,v.count]}] end |
#where(conditions) ⇒ Object
9 10 11 |
# File 'lib/simple_tables/table.rb', line 9 def where(conditions) @data.select { |r| r.matches?(conditions) } end |