Class: FortyFacets::Filter

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

Overview

Base class for the objects representing a specific value for a specific type of filter. Most FilterDefinitions will have their own Filter subclass to control values for display and rendering to request parameters.

Defined Under Namespace

Classes: FacetValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#definitionObject

Returns the value of attribute definition

Returns:

  • (Object)

    the current value of definition



5
6
7
# File 'lib/forty_facets/filter.rb', line 5

def definition
  @definition
end

#search_instanceObject

Returns the value of attribute search_instance

Returns:

  • (Object)

    the current value of search_instance



5
6
7
# File 'lib/forty_facets/filter.rb', line 5

def search_instance
  @search_instance
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



5
6
7
# File 'lib/forty_facets/filter.rb', line 5

def value
  @value
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  value.nil? || value == '' || value == []
end

#nameObject



8
9
10
# File 'lib/forty_facets/filter.rb', line 8

def name
  definition.options[:name] || definition.path.join(' ')
end

#withoutObject

generate a search with this filter removed



17
18
19
20
21
22
23
# File 'lib/forty_facets/filter.rb', line 17

def without
  search = search_instance
  return search if empty?
  new_params = search_instance.params || {}
  new_params.delete(definition.request_param)
  search_instance.class.new_unwrapped(new_params, search_instance.root)
end