Class: Multisync::Catalog::Filter
- Inherits:
-
Object
- Object
- Multisync::Catalog::Filter
- Defined in:
- lib/multisync/catalog/filter.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
selected subjects.
-
#sets ⇒ Object
readonly
selected sets.
Instance Method Summary collapse
-
#initialize(sets) ⇒ Filter
constructor
A new instance of Filter.
- #selected?(subject) ⇒ Boolean
- #visit(subject, _level) ⇒ Object
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
#result ⇒ Object (readonly)
selected subjects
7 8 9 |
# File 'lib/multisync/catalog/filter.rb', line 7 def result @result end |
#sets ⇒ Object (readonly)
selected sets
4 5 6 |
# File 'lib/multisync/catalog/filter.rb', line 4 def sets @sets end |
Instance Method Details
#selected?(subject) ⇒ 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 |