Class: Blacklight::Hierarchy::FacetTree
- Inherits:
-
Object
- Object
- Blacklight::Hierarchy::FacetTree
- Defined in:
- app/models/blacklight/hierarchy/facet_tree.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#facet_config ⇒ Object
readonly
Returns the value of attribute facet_config.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(prefix:, facet_display:, facet_field:) ⇒ FacetTree
constructor
A new instance of FacetTree.
- #split_regex ⇒ Object
Constructor Details
#initialize(prefix:, facet_display:, facet_field:) ⇒ FacetTree
Returns a new instance of FacetTree.
10 11 12 13 14 |
# File 'app/models/blacklight/hierarchy/facet_tree.rb', line 10 def initialize(prefix:, facet_display:, facet_field:) @prefix = prefix @facet_config = facet_display.dig(:hierarchy, prefix) @facet_field = facet_field end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
16 17 18 |
# File 'app/models/blacklight/hierarchy/facet_tree.rb', line 16 def data @data end |
#facet_config ⇒ Object (readonly)
Returns the value of attribute facet_config.
16 17 18 |
# File 'app/models/blacklight/hierarchy/facet_tree.rb', line 16 def facet_config @facet_config end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
16 17 18 |
# File 'app/models/blacklight/hierarchy/facet_tree.rb', line 16 def prefix @prefix end |
Class Method Details
.build(prefix:, facet_display:, facet_field:) ⇒ Object
6 7 8 |
# File 'app/models/blacklight/hierarchy/facet_tree.rb', line 6 def self.build(prefix:, facet_display:, facet_field:) new(prefix: prefix, facet_display: facet_display, facet_field: facet_field).build end |
Instance Method Details
#build ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/blacklight/hierarchy/facet_tree.rb', line 18 def build return unless facet_config {}.tap do |tree| facet_config.first.each do |key| # TODO: remove baked in notion of underscores being part of the blacklight facet field names facet_field = [prefix, key].compact.join('_') tree[facet_field] ||= {} data = @facet_field.display_facet next if data.nil? data.items.each do |facet_item| path = facet_item.value.split(split_regex) loc = tree[facet_field] loc = loc[path.shift] ||= {} while path.length > 0 loc[:_] = HierarchicalFacetItem.new(facet_item.value, facet_item.value.split(split_regex).last, facet_item.hits) end end end end |
#split_regex ⇒ Object
37 38 39 |
# File 'app/models/blacklight/hierarchy/facet_tree.rb', line 37 def split_regex @split_regex ||= Regexp.new("\s*#{Regexp.escape(facet_config.length >= 2 ? facet_config[1] : ':')}\s*") end |