Class: Gum::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/gum/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param, field, options) ⇒ Filter

Returns a new instance of Filter.



5
6
7
8
9
# File 'lib/gum/filter.rb', line 5

def initialize(param, field, options)
  @param = param
  @field = field
  @options = options || {}
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



3
4
5
# File 'lib/gum/filter.rb', line 3

def field
  @field
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/gum/filter.rb', line 3

def options
  @options
end

#paramObject (readonly)

Returns the value of attribute param.



3
4
5
# File 'lib/gum/filter.rb', line 3

def param
  @param
end

Instance Method Details

#__render__(value) ⇒ Object

Raises:

  • (NoMethodError)


24
25
26
# File 'lib/gum/filter.rb', line 24

def __render__(value)
  raise NoMethodError
end

#empty?(params) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/gum/filter.rb', line 20

def empty?(params)
  params[param].blank?
end

#render(params) ⇒ Object



11
12
13
14
# File 'lib/gum/filter.rb', line 11

def render(params)
  return if empty?(params)
  __render__ value_from(params)
end

#value_from(params) ⇒ Object



16
17
18
# File 'lib/gum/filter.rb', line 16

def value_from(params)
  params[param].presence
end