Class: FacetedSearch::Facets

Inherits:
Object
  • Object
show all
Defined in:
app/models/faceted_search/facets.rb

Defined Under Namespace

Classes: Checkboxes, Date, Default, DefaultList, FullTree, List, PrimitiveList, Text, Tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Facets

Returns a new instance of Facets.



5
6
7
8
9
10
11
12
13
14
15
# File 'app/models/faceted_search/facets.rb', line 5

def initialize(params)
  if params.is_a? ActionController::Parameters
    @params = params.to_unsafe_hash
  elsif params.is_a? Hash
    @params = params
  else
    @params = {}
  end
  @params = @params.symbolize_keys
  @list = []
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



3
4
5
# File 'app/models/faceted_search/facets.rb', line 3

def list
  @list
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'app/models/faceted_search/facets.rb', line 3

def model
  @model
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'app/models/faceted_search/facets.rb', line 3

def params
  @params
end

Instance Method Details

#model_table_nameObject



38
39
40
# File 'app/models/faceted_search/facets.rb', line 38

def model_table_name
  @model.table_name
end

#pathObject



17
18
19
# File 'app/models/faceted_search/facets.rb', line 17

def path
  '?facets'
end

#path_for(facet, value) ⇒ Object



21
22
23
24
25
26
27
28
# File 'app/models/faceted_search/facets.rb', line 21

def path_for(facet, value)
  p = path
  list.each do |current_facet|
    p += current_facet == facet ? current_facet.path_for(value)
                                : current_facet.path
  end
  p
end

#resultsObject



30
31
32
33
34
35
36
# File 'app/models/faceted_search/facets.rb', line 30

def results
  scope = @model
  list.each do |facet|
    scope = facet.add_scope(scope)
  end
  scope.distinct
end