Sha256: ebf5ec08ca9ad44eb9bda430970221c24da369633b9ca4ed94d57cc28e978983

Contents?: true

Size: 588 Bytes

Versions: 4

Compression:

Stored size: 588 Bytes

Contents

module PivotTable
  module CellCollection

    ACCESSORS = [:header, :data, :value_name, :orthogonal_headers]

    ACCESSORS.each do |a|
      self.send(:attr_accessor, a)
    end

    def initialize(options = {})
      ACCESSORS.each do |a|
        self.send("#{a}=", options[a]) if options.has_key?(a)
      end
    end

    def total
      data.inject(0) { |t, x| t + (x ? x.send(value_name) : 0) }
    end

  private

    def find_data by_header_name
      data[
        orthogonal_headers.find_index{|header| by_header_name.to_s == header.to_s}
      ] rescue nil
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pivot_table-1.0.0 lib/pivot_table/cell_collection.rb
pivot_table-0.5.0 lib/pivot_table/cell_collection.rb
pivot_table-0.4.0 lib/pivot_table/cell_collection.rb
pivot_table-0.3.0 lib/pivot_table/cell_collection.rb