Class: LcpRuby::Search::RelativeDateExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/search/relative_date_expander.rb

Constant Summary collapse

RELATIVE_SUFFIXES =

Expands relative date operator params (e.g., release_date_this_month=1) into Ransack-compatible gteq/lteq date range params.

Called before Ransack so that custom date operators are resolved to absolute date ranges that Ransack understands.

OperatorRegistry::RELATIVE_DATE_OPERATORS.map(&:to_s).freeze

Class Method Summary collapse

Class Method Details

.expand(filter_params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lcp_ruby/search/relative_date_expander.rb', line 11

def self.expand(filter_params)
  return filter_params if filter_params.blank?

  expanded = {}
  filter_params.each do |key, value|
    suffix = matching_suffix(key)
    if suffix
      field = key.to_s.chomp("_#{suffix}")
      expand_operator(expanded, field, suffix.to_sym, value)
    else
      expanded[key] = value
    end
  end
  expanded
end