Sha256: 67197f89c8fd7ac1529a2736143f46785a2cbcb1c9181e9ab812661b42647660

Contents?: true

Size: 771 Bytes

Versions: 9

Compression:

Stored size: 771 Bytes

Contents

module ActiveReporter
  module Aggregator
    class Ratio < ActiveReporter::Aggregator::Base
      attr_reader :numerator, :denominator

      def function
        "(#{numerator}/NULLIF(#{denominator},0))"
      end

      private

      def numerator
        raise "Ratio aggregator must specify a numerator column" unless opts.include?(:numerator)
        @numerator = report.aggregators[opts[:numerator].to_sym].try(:function) || "#{report.table_name}.#{opts[:numerator]}"
      end

      def denominator
        raise "Ratio aggregator must specify a denominator column" unless opts.include?(:denominator)
        @denominator = report.aggregators[opts[:denominator].to_sym].try(:function) || "#{report.table_name}.#{opts[:denominator]}"
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_reporter-0.6.2 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.6.1 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.6.0 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.5.13 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.5.12 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.5.11 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.5.10 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.5.9 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.5.8 lib/active_reporter/aggregator/ratio.rb