Class: Percolate::Facet::TagFacet

Inherits:
BaseFacet
  • Object
show all
Defined in:
lib/percolate/facet/tag_facet.rb

Overview

A facet for looking up entities based on collections of tags.

Defined Under Namespace

Classes: TagPoset

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(poset_root = nil) ⇒ TagFacet

Returns a new instance of TagFacet.



31
32
33
# File 'lib/percolate/facet/tag_facet.rb', line 31

def initialize(poset_root = nil)
  @poset_root = poset_root
end

Instance Attribute Details

#poset_rootObject (readonly)

Returns the value of attribute poset_root.



29
30
31
# File 'lib/percolate/facet/tag_facet.rb', line 29

def poset_root
  @poset_root
end

Instance Method Details

#find(tags) ⇒ Object



48
49
50
# File 'lib/percolate/facet/tag_facet.rb', line 48

def find(tags)
  @poset_root.matches(tags).sort
end

#merge(other) ⇒ Object

Raises:

  • (ArgumentError)


52
53
54
55
56
# File 'lib/percolate/facet/tag_facet.rb', line 52

def merge(other)
  raise ArgumentError, "Please provide another #{self.class}" if !other.is_a?(TagFacet)

  TagFacet.new(@poset_root.merge(other.poset_root))
end

#rules=(rules_hash) ⇒ Object

Sets the tag lookup rules.

Parameters:

  • rules_hash (Hash)

    the lookup rules.



38
39
40
41
42
43
44
45
46
# File 'lib/percolate/facet/tag_facet.rb', line 38

def rules=(rules_hash)
  @poset_root = TagPoset.new

  rules_hash.each do |rule_hash|
    @poset_root.insert(rule_hash["tags"], rule_hash["value"])
  end

  rules_hash
end