Class: Blacklight::FacetItemPivotPresenter

Inherits:
FacetItemPresenter show all
Defined in:
app/presenters/blacklight/facet_item_pivot_presenter.rb

Instance Attribute Summary

Attributes inherited from FacetItemPresenter

#facet_config, #facet_field, #facet_item, #search_state, #view_context

Instance Method Summary collapse

Methods inherited from FacetItemPresenter

#add_href, #constraint_label, #hits, #href, #initialize, #items, #remove_href

Constructor Details

This class inherits a constructor from Blacklight::FacetItemPresenter

Instance Method Details

#facet_item_presenter(facet_item) ⇒ Object



27
28
29
# File 'app/presenters/blacklight/facet_item_pivot_presenter.rb', line 27

def facet_item_presenter(facet_item)
  facet_config.item_presenter.new(facet_item, facet_config, view_context, facet_field, search_state)
end

#facet_item_presentersObject



20
21
22
23
24
25
# File 'app/presenters/blacklight/facet_item_pivot_presenter.rb', line 20

def facet_item_presenters
  return to_enum(:facet_item_presenters) unless block_given?
  return [] unless items

  items.each { |i| yield facet_item_presenter(i) }
end

#field_labelObject



16
17
18
# File 'app/presenters/blacklight/facet_item_pivot_presenter.rb', line 16

def field_label
  facet_field_presenter.label
end

#labelString

Get the displayable version of a facet’s value

Returns:

  • (String)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/presenters/blacklight/facet_item_pivot_presenter.rb', line 35

def label
  label_source = facet_item.respond_to?(:label) ? facet_item.label : facet_item
  if facet_config.helper_method
    view_context.public_send(facet_config.helper_method, label_source)
  else
    item_fq = label_source.respond_to?(:fq) ? label_source.fq : {}
    item_fq = item_fq.symbolize_keys
    label_value = facet_config.pivot.map(&:to_sym).map { |k| item_fq[k] }
    if label_source.respond_to?(:field)
      label_value << value
    else
      label_value.unshift value
    end
    label_value.compact.join(" » ")
  end
end

#selected?Boolean

Check if the query parameters have the given facet field with the given value.

Returns:

  • (Boolean)


8
9
10
# File 'app/presenters/blacklight/facet_item_pivot_presenter.rb', line 8

def selected?
  search_state.filter(facet_config).include?(facet_item)
end

#shown?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'app/presenters/blacklight/facet_item_pivot_presenter.rb', line 12

def shown?
  selected? || facet_item_presenters.any? { |x| x.try(:shown?) }
end

#valueObject



52
53
54
55
56
57
58
# File 'app/presenters/blacklight/facet_item_pivot_presenter.rb', line 52

def value
  if facet_item.respond_to? :value
    facet_item.value
  else
    facet_item
  end
end