Module: ByStar::Calculations::Count

Included in:
ByStar::Calculations
Defined in:
lib/by_star/calculations/count.rb

Instance Method Summary collapse

Instance Method Details

#count_by_month(field = nil, month = Time.now.month, options = {}, &block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/by_star/calculations/count.rb', line 11

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

#count_by_year(field = nil, year = Time.zone.now.year, options = {}, &block) ⇒ Object



4
5
6
7
8
9
# File 'lib/by_star/calculations/count.rb', line 4

def count_by_year(field=nil, year=Time.zone.now.year, options={}, &block)
  db_field = options.delete(:field)
  scoped_by(block) do
    count(field, { :conditions => conditions_for_range(start_of_year(year), end_of_year(year), db_field) }.reverse_merge!(options))
  end
end