Sha256: ac99b100b1aa7cb42a23ccaed501bb8513af2be32a310b809ea23f8236589289

Contents?: true

Size: 703 Bytes

Versions: 6

Compression:

Stored size: 703 Bytes

Contents

module ByStar
  module Calculations
    module Sum
      def sum_by_year(field, year=Time.zone.now.year, options={}, &block)
        scoped_by(block) do
          sum(field, { :conditions => conditions_for_range(start_of_year(year), end_of_year(year), options.delete(:field)) }.reverse_merge!(options))
        end
      end

      def sum_by_month(field, month=Time.zone.now.month, options={}, &block)
        year, month = work_out_month(month, options.delete(:year))
        scoped_by(block) do
          sum(field, { :conditions => conditions_for_range(start_of_month(month, year), end_of_month(month, year), options.delete(:field)) }.reverse_merge!(options))
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
by_star-0.6.1 lib/calculations/sum.rb
by_star-0.6.0 lib/calculations/sum.rb
by_star-0.5.2 lib/calculations/sum.rb
by_star-0.5.1 lib/calculations/sum.rb
by_star-0.5.0 lib/calculations/sum.rb
by_star-0.4.0 lib/calculations/sum.rb