Class: Swa::CLI::Selector
- Inherits:
-
Object
- Object
- Swa::CLI::Selector
- Defined in:
- lib/swa/cli/selector.rb
Instance Method Summary collapse
- #add(&block) ⇒ Object
- #apply(collection) ⇒ Object
- #call(subject) ⇒ Object
-
#initialize ⇒ Selector
constructor
A new instance of Selector.
- #specified? ⇒ Boolean
Constructor Details
#initialize ⇒ Selector
Returns a new instance of Selector.
6 7 8 |
# File 'lib/swa/cli/selector.rb', line 6 def initialize @predicates = [] end |
Instance Method Details
#add(&block) ⇒ Object
10 11 12 |
# File 'lib/swa/cli/selector.rb', line 10 def add(&block) @predicates << block end |
#apply(collection) ⇒ Object
20 21 22 |
# File 'lib/swa/cli/selector.rb', line 20 def apply(collection) collection.lazy.select(&method(:call)) end |
#call(subject) ⇒ Object
14 15 16 17 18 |
# File 'lib/swa/cli/selector.rb', line 14 def call(subject) @predicates.all? do |predicate| predicate.call(subject) end end |
#specified? ⇒ Boolean
24 25 26 |
# File 'lib/swa/cli/selector.rb', line 24 def specified? @predicates.any? end |