Module: DmFilter::ClassMethods

Extended by:
ClassMethods
Included in:
ClassMethods
Defined in:
lib/dm_filter.rb

Overview

Class Method

Instance Method Summary collapse

Instance Method Details

#dm_get(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dm_filter.rb', line 9

def dm_get(options)
  options[:column_date] = 'created_at' unless options[:column_date].present?

  from = options[:from].blank? ? Time.current : options[:from].to_datetime
  to = options[:to].blank? ? Time.current : options[:to].to_datetime

  case options[:duration]
  when 'all'
    all
  when 'today'
    where(options[:column_date] => from.beginning_of_day..to.end_of_day)
  when 'yesterday'
    where(options[:column_date] => from.yesterday.beginning_of_day..to.yesterday.end_of_day)
  when 'this_week'
    where(options[:column_date] => from.beginning_of_week..to.end_of_week)
  when 'this_month'
    where(options[:column_date] => from.beginning_of_month..to.end_of_month)
  when 'last_month'
    where(options[:column_date] => from.last_month.beginning_of_month..to.last_month.end_of_month)
  when 'period', 'custom'
    where(options[:column_date] => from.beginning_of_day..to.end_of_day)
  else
    all
  end
end