Sha256: d5166a8013a0d752eb016a2c7f55ddacb66633045daa1481191212bb0f49b85a

Contents?: true

Size: 1.22 KB

Versions: 11

Compression:

Stored size: 1.22 KB

Contents

module Martyr
  module Runtime

    # Requirements:
    #   The object must have the #store method

    module ElementCommon
      extend ActiveSupport::Concern

      included do
        attr_reader :metrics_hash
      end

      # Grain and coordinates are different.
      # Coordinates can include "background" multi-value slices such as: 'media.types' => ['a', 'b', 'c']
      # Grain always have one value for each level
      # Coordinates always include the grain.

      def grain_has_level_id?(level_id)
        grain_level_ids.include?(level_id)
      end

      def coordinates_have_level_id?(level_id)
        coordinates.keys.include?(level_id)
      end
      alias_method :has_level_id?, :coordinates_have_level_id?

      def metrics
        metrics_hash.values
      end

      def metric_ids
        metrics_hash.keys
      end

      # @param metrics [Array<BaseMetric>]
      # @return [self]
      def rollup(*metrics)
        @metrics_hash ||= {}
        metrics.each do |metric|
          next if @metrics_hash[metric.id]
          value = empty? ? 0 : FutureMetric.wrap(self, metric, :rollup)
          store metric.id, value
          @metrics_hash[metric.id] = metric
        end
        self
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
martyr-0.1.85.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.84.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.82.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.81.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.80.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.79.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.78.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.77.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.76.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.75.pre lib/martyr/runtime/data_set/element_common.rb
martyr-0.1.74.pre lib/martyr/runtime/data_set/element_common.rb