Module: Reductor::Reductions::CountsByDay

Defined in:
lib/reductor/reductions/counts_by_day.rb

Instance Method Summary collapse

Instance Method Details

#datetime_fieldObject



5
6
7
# File 'lib/reductor/reductions/counts_by_day.rb', line 5

def datetime_field
  @options[:field] || 'created_at'
end

#mapObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/reductor/reductions/counts_by_day.rb', line 9

def map
  %Q{
    function() {
      if(this.#{datetime_field}){
        date = new Date(this.#{datetime_field}.getFullYear(), this.#{datetime_field}.getMonth(), this.#{datetime_field}.getDate());
        } else {
          date = null;
        }
        emit(date , 1);
      }
  }
end

#reduceObject



22
23
24
25
26
27
28
# File 'lib/reductor/reductions/counts_by_day.rb', line 22

def reduce
  %Q{
    function(key, values) {
      return Array.sum(values);
    }
  }
end