Class: Magick::Targeting::Complex

Inherits:
Base
  • Object
show all
Defined in:
lib/magick/targeting/complex.rb

Instance Method Summary collapse

Constructor Details

#initialize(conditions, operator: :and) ⇒ Complex

Returns a new instance of Complex.



6
7
8
9
# File 'lib/magick/targeting/complex.rb', line 6

def initialize(conditions, operator: :and)
  @conditions = Array(conditions)
  @operator = operator.to_sym
end

Instance Method Details

#matches?(context) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/magick/targeting/complex.rb', line 11

def matches?(context)
  return false if @conditions.empty?

  results = @conditions.map { |condition| condition.matches?(context) }

  case @operator
  when :and, :all
    results.all?
  when :or, :any
    results.any?
  else
    false
  end
end