Sha256: 544bcbbeb1afd106b451ffa63231ab8dbdc6cdac7576b2e58f40e0edddd579ca

Contents?: true

Size: 691 Bytes

Versions: 4

Compression:

Stored size: 691 Bytes

Contents

module Dorsale
  module BillingMachine
    module SmallData
      class FilterStrategyByTimePeriod < ::Dorsale::SmallData::FilterStrategyByKeyValue
        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
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dorsale-3.0.3 app/models/dorsale/billing_machine/small_data/filter_strategy_by_time_period.rb
dorsale-3.0.2 app/models/dorsale/billing_machine/small_data/filter_strategy_by_time_period.rb
dorsale-3.0.1 app/models/dorsale/billing_machine/small_data/filter_strategy_by_time_period.rb
dorsale-3.0.0 app/models/dorsale/billing_machine/small_data/filter_strategy_by_time_period.rb