Sha256: fdffaeef01294bc8c94cca1c9f61224381f001101159285840b865efb4e84dcb

Contents?: true

Size: 778 Bytes

Versions: 4

Compression:

Stored size: 778 Bytes

Contents

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

      def function
        "(#{numerator}/NULLIF(#{denominator},0)::FLOAT)"
      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

4 entries across 4 versions & 1 rubygems

Version Path
active_reporter-0.7.1 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.6.5 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.6.4 lib/active_reporter/aggregator/ratio.rb
active_reporter-0.6.3 lib/active_reporter/aggregator/ratio.rb