Module: DmFilter::ClassMethods
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() [:column_date] = 'created_at' unless [:column_date].present? from = [:from].blank? ? Time.current : [:from].to_datetime to = [:to].blank? ? Time.current : [:to].to_datetime case [:duration] when 'all' all when 'today' where([:column_date] => from.beginning_of_day..to.end_of_day) when 'yesterday' where([:column_date] => from.yesterday.beginning_of_day..to.yesterday.end_of_day) when 'this_week' where([:column_date] => from.beginning_of_week..to.end_of_week) when 'this_month' where([:column_date] => from.beginning_of_month..to.end_of_month) when 'last_month' where([:column_date] => from.last_month.beginning_of_month..to.last_month.end_of_month) when 'period', 'custom' where([:column_date] => from.beginning_of_day..to.end_of_day) else all end end |