Class: Multisync::Catalog::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/multisync/catalog/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sets) ⇒ Filter

Returns a new instance of Filter.



9
10
11
12
# File 'lib/multisync/catalog/filter.rb', line 9

def initialize sets
  @sets = Array(sets)
  @result = []
end

Instance Attribute Details

#resultObject (readonly)

selected subjects



7
8
9
# File 'lib/multisync/catalog/filter.rb', line 7

def result
  @result
end

#setsObject (readonly)

selected sets



4
5
6
# File 'lib/multisync/catalog/filter.rb', line 4

def sets
  @sets
end

Instance Method Details

#selected?(subject) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'lib/multisync/catalog/filter.rb', line 18

def selected? subject
  # only return the leaves of the definition tree
  return false unless subject.members.empty?
  # no sets defined, but subject is in the default set
  return true if sets.empty? && subject.default?
  # subject matches any of the given sets
  sets.any? {|set| /\b#{set}\b/.match subject.fullname }
end

#visit(subject, _level) ⇒ Object



14
15
16
# File 'lib/multisync/catalog/filter.rb', line 14

def visit subject, _level
  result << subject if selected?(subject)
end