Sha256: a663afd99963f886b9f3fca088548b283971135df6d33a05d85b1d601b340581

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

module ReportsKit
  module Reports
    module Data
      class AggregateTwoDimensions
        attr_accessor :series, :dimension, :second_dimension

        def initialize(series)
          self.series = series
          self.dimension = series.dimensions[0]
          self.second_dimension = series.dimensions[1]
        end

        def perform
          dimension_keys_values
        end

        private

        def dimension_keys_values
          relation = series.filtered_relation
          relation = relation.group(dimension.group_expression, second_dimension.group_expression)
          relation = relation.joins(dimension.joins) if dimension.joins
          relation = relation.joins(second_dimension.joins) if second_dimension.joins
          relation = relation.order(order)
          relation = series.edit_relation_method.call(relation) if series.edit_relation_method
          dimension_keys_values = relation.distinct.public_send(*series.aggregate_function)
          dimension_keys_values = Utils.populate_sparse_hash(dimension_keys_values, dimension: dimension)
          dimension_keys_values.delete(nil)
          dimension_keys_values.delete('')
          Hash[dimension_keys_values]
        end

        def order
          dimension.configured_by_time? ? '2' : '1 DESC'
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
reports_kit-0.7.1 lib/reports_kit/reports/data/aggregate_two_dimensions.rb
reports_kit-0.7.0 lib/reports_kit/reports/data/aggregate_two_dimensions.rb
reports_kit-0.5.0 lib/reports_kit/reports/data/aggregate_two_dimensions.rb
reports_kit-0.4.1 lib/reports_kit/reports/data/aggregate_two_dimensions.rb
reports_kit-0.4.0 lib/reports_kit/reports/data/aggregate_two_dimensions.rb
reports_kit-0.3.3 lib/reports_kit/reports/data/aggregate_two_dimensions.rb
reports_kit-0.3.2 lib/reports_kit/reports/data/aggregate_two_dimensions.rb
reports_kit-0.3.1 lib/reports_kit/reports/data/aggregate_two_dimensions.rb
reports_kit-0.3.0 lib/reports_kit/reports/data/aggregate_two_dimensions.rb