Class: Plutonium::Query::Filters::DateRange
- Inherits:
-
Plutonium::Query::Filter
- Object
- Base
- Plutonium::Query::Filter
- Plutonium::Query::Filters::DateRange
- Defined in:
- lib/plutonium/query/filters/date_range.rb
Overview
DateRange filter for filtering between two dates
Instance Attribute Summary
Attributes inherited from Plutonium::Query::Filter
Instance Method Summary collapse
- #apply(scope, from: nil, to: nil) ⇒ Object
- #customize_inputs ⇒ Object
-
#initialize(from_label: nil, to_label: nil) ⇒ DateRange
constructor
A new instance of DateRange.
Methods inherited from Plutonium::Query::Filter
Methods included from Definition::Presentable
Constructor Details
#initialize(from_label: nil, to_label: nil) ⇒ DateRange
Returns a new instance of DateRange.
13 14 15 16 17 |
# File 'lib/plutonium/query/filters/date_range.rb', line 13 def initialize(from_label: nil, to_label: nil, **) super(**) @from_label = from_label @to_label = to_label end |
Instance Method Details
#apply(scope, from: nil, to: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/plutonium/query/filters/date_range.rb', line 19 def apply(scope, from: nil, to: nil) from_date = parse_date(from) to_date = parse_date(to) if from_date && to_date scope.where(key => from_date.beginning_of_day..to_date.end_of_day) elsif from_date scope.where(key => from_date.beginning_of_day..) elsif to_date scope.where(key => ..to_date.end_of_day) else scope end end |
#customize_inputs ⇒ Object
34 35 36 37 38 39 |
# File 'lib/plutonium/query/filters/date_range.rb', line 34 def customize_inputs input :from, as: :date input :to, as: :date field :from, placeholder: @from_label || "#{key.to_s.humanize} from..." field :to, placeholder: @to_label || "#{key.to_s.humanize} to..." end |