Class: Paraphrase::ParamsFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/paraphrase/params_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unfiltered_params, keys) ⇒ ParamsFilter

Returns a new instance of ParamsFilter.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/paraphrase/params_filter.rb', line 5

def initialize(unfiltered_params, keys)
  @params = unfiltered_params.with_indifferent_access.slice(*keys)

  @result = @params.inject(HashWithIndifferentAccess.new) do |result, (key, value)|
    value = @params[key]

    if respond_to?(key)
      value = send(key)
    end

    value = scrub(value)

    if value.present?
      result[key] = value
    end

    result
  end
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/paraphrase/params_filter.rb', line 3

def params
  @params
end

#resultObject (readonly)

Returns the value of attribute result.



3
4
5
# File 'lib/paraphrase/params_filter.rb', line 3

def result
  @result
end