class SimpleTables::Table

Attributes

data[R]

Public Class Methods

new(data,col_names) click to toggle source
# File lib/simple_tables/table.rb, line 5
def initialize(data,col_names)
  @data=data.map{|r| Record.new(r,col_names)}
end

Public Instance Methods

pivot(rows_col,cols_col,&block) click to toggle source
# 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) click to toggle source
# File lib/simple_tables/table.rb, line 9
def where(conditions)
  @data.select { |r| r.matches?(conditions) }
end