Class: Swa::CLI::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/swa/cli/selector.rb

Instance Method Summary collapse

Constructor Details

#initializeSelector

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

Returns:

  • (Boolean)


24
25
26
# File 'lib/swa/cli/selector.rb', line 24

def specified?
  @predicates.any?
end