README.markdown in by_star-0.2.5 vs README.markdown in by_star-0.3.0

- old
+ new

@@ -22,11 +22,21 @@ { :include => "tags", :conditions => ["tags.name = ?", 'ruby'] } end If you're not using the standard `created_at` field: don't worry! I've covered that scenario too. +## count_by* methods +`count_by` methods can be scoped to only count those records which have a specific field set, and you do this by specifying the symbol version of the name of the field, e.g; + + Invoice.count_by_year(:value) + +If you want to specify further arguments but do not care about the scoped field: + + Invoice.count_by_year(:all, 2009) + + ## By Year (`by_year`) To find records based on a year you can pass it a two or four digit number: Post.by_year(09) @@ -35,10 +45,45 @@ Post.by_year(99) will return all the posts in the year 1999. +You can also specify the full year: + + Post.by_year(2009) + Post.by_year(1999) + +When you specify a year *less than* 1902 and *greater than* 2039 using specific versions of Ruby (i.e. 1.8.6p114) an `ArgumentError` will be raised. We recommend you upgrade Ruby to *at least* 1.8.7 to stop this problem occuring. + +## Sum By Year (`sum_by_year`) + +To sum records for the current year based on a field: + + Invoice.sum_by_year(:value) + +To sum records for a year based on a field: + + Invoice.sum_by_year(:value, 09) + +You can also pass it a full year: + + Invoice.sum_by_year(:value, 2009) + +## Count By Year (`count_by_year`) + +To count the records in the current year regardless of field: + + Invoice.count_by_year + +To count records in the current year where only a specific field is set: + + Invoice.count_by_year(:value) + +To count records in a different year regardless of field: + + Invoice.count_by_year(:all, :year => 2009) + ## By Month (`by_month`) If you know the number of the month you want: Post.by_month(1) @@ -65,9 +110,52 @@ Post.by_month(Time.local(2008, 11, 24)) This will find all the posts in November 2008. +When you specify a year *less than* 1902 and *greater than* 2039 using specific versions of Ruby (i.e. 1.8.6p114) an `ArgumentError` will be raised. We recommend you upgrade Ruby to *at least* 1.8.7 to stop this problem occuring. + + +## Sum By Month (`sum_by_month`) + +To sum records for the current month: + + Invoice.sum_by_month + +To sum records for a numbered month based on a field: + + Invoice.sum_by_month(:value, 9) + +You can also specify the name of the month: + + Invoice.sum_by_month(:value, "September") + +You can also lookup on a different year: + + Invoice.sum_by_year(:value, 9, :year => "2009") + +## Count By Month (`count_by_month`) + +To count records for the current month regardless of field: + + Invoice.count_by_month + +To count records for the current month where only a specific field is set: + + Invoice.count_by_month(:value) + +To count records for a different month regardless of field: + + Invoice.count_by_month(:all, 9) + +To count records for a different month in the current year: + + Invoice.count_by_month(:number, 9) + +To count records for a different month in a different year: + + Invoice.count_by_month(:number, 9, :year => 2008) + ## By Fortnight (`by_fortnight`) Fortnight numbering starts at 0. The beginning of a fortnight is Monday, 12am. To find records from the current fortnight: \ No newline at end of file