Class: Dorsale::BillingMachine::SmallData::FilterStrategyByTimePeriod

Inherits:
SmallData::FilterStrategyByKeyValue show all
Defined in:
app/models/dorsale/billing_machine/small_data/filter_strategy_by_time_period.rb

Instance Attribute Summary

Attributes inherited from SmallData::FilterStrategyByKeyValue

#key

Instance Method Summary collapse

Methods inherited from SmallData::FilterStrategyByKeyValue

#initialize

Constructor Details

This class inherits a constructor from Dorsale::SmallData::FilterStrategyByKeyValue

Instance Method Details

#apply(query, value) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/dorsale/billing_machine/small_data/filter_strategy_by_time_period.rb', line 5

def apply(query, value)
  criteria = "#{query.model.table_name}.#{key}"

  if value == "today"
    return query.where("#{criteria} >= ?", Time.zone.now.to_date)
  elsif value == "week"
    return query.where("#{criteria} >= ?", Time.zone.now.to_date.at_beginning_of_week)
  elsif value == "month"
    return query.where("#{criteria} >= ?", Time.zone.now.to_date.at_beginning_of_month)
  else
    return query
  end
end