Sha256: 32146b1ce17d662eba6c5119e47fbb9654e6e178c4b1d42417175c5fcf22ebc0

Contents?: true

Size: 840 Bytes

Versions: 5

Compression:

Stored size: 840 Bytes

Contents

module FortyFacets
  # 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.
  Filter = Struct.new(:definition, :search_instance, :value) do
    FacetValue = Struct.new(:entity, :count, :selected)

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

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

    # generate a search with this filter removed
    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
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
forty_facets-0.2.1 lib/forty_facets/filter.rb
forty_facets-0.2 lib/forty_facets/filter.rb
forty_facets-0.1.9.1 lib/forty_facets/filter.rb
forty_facets-0.1.9.0 lib/forty_facets/filter.rb
forty_facets-0.1.8.9 lib/forty_facets/filter.rb