Sha256: 953715f4205100713b2fea95504642730394400dc68515742aea6acfe7445381

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 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
      
      def sum_by_day(field, day=Time.zone.now, options={}, &block)
        scoped_by(block) do
          day = parse(day)
          sum(field, { :conditions => conditions_for_range(day.beginning_of_day, day.end_of_day, options.delete(:field)) }.reverse_merge!(options))
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
by_star-0.6.3 lib/calculations/sum.rb
by_star-0.6.2 lib/calculations/sum.rb