Class: Huginn::Datatable::FilterNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/huginn/datatable/filter_normalizer.rb

Overview

Normalizes the heterogeneous filter payloads sent by frontends (ActionController::Parameters, Hash, Array of hashes, [key, value] pairs, ...) into a single Hash of { column => Array(values) }.

Values are accumulated in arrays so that repeated keys produce an IN condition when applied as a datatable filter. Invalid payload shapes are simply ignored, and keys are normalized to strings.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ FilterNormalizer

Returns a new instance of FilterNormalizer.



17
18
19
# File 'lib/huginn/datatable/filter_normalizer.rb', line 17

def initialize(raw)
  @raw = raw
end

Class Method Details

.call(raw) ⇒ Object



13
14
15
# File 'lib/huginn/datatable/filter_normalizer.rb', line 13

def self.call(raw)
  new(raw).call
end

Instance Method Details

#callObject



21
22
23
24
25
# File 'lib/huginn/datatable/filter_normalizer.rb', line 21

def call
  each_pair(@raw).each_with_object({}) do |(key, value), acc|
    (acc[key.to_s] ||= []) << value
  end
end