lib/pivot_table/grid.rb in pivot_table-0.1.4 vs lib/pivot_table/grid.rb in pivot_table-0.2.0
- old
+ new
@@ -1,13 +1,18 @@
module PivotTable
class Grid
attr_accessor :source_data, :row_name, :column_name, :value_name
- attr_reader :columns, :rows, :data_grid
+ attr_reader :columns, :rows, :data_grid, :configuration
- def initialize(&block)
+ DEFAULT_OPTIONS = {
+ :sort => true
+ }
+
+ def initialize(opts = {}, &block)
yield(self) if block_given?
+ @configuration = Configuration.new(DEFAULT_OPTIONS.merge(opts))
end
def build
populate_grid
build_rows
@@ -78,10 +83,11 @@
end
private
def headers(method)
- @source_data.collect { |c| c.send method }.uniq.sort
+ hdrs = @source_data.collect { |c| c.send method }.uniq
+ configuration.sort ? hdrs.sort : hdrs
end
end
end