Class: Erlectricity::StaticCondition

Inherits:
Condition
  • Object
show all
Defined in:
lib/erlectricity/conditions/static.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Condition

for

Constructor Details

#initialize(value) ⇒ StaticCondition

Returns a new instance of StaticCondition.



4
5
6
7
8
9
10
11
12
# File 'lib/erlectricity/conditions/static.rb', line 4

def initialize(value)
  if value.is_a?(Array)
    self.value = value.map do |v|
      Condition.for(v)
    end
  else
    self.value = value
  end
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/erlectricity/conditions/static.rb', line 3

def value
  @value
end

Instance Method Details

#binding_for(arg) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/erlectricity/conditions/static.rb', line 26

def binding_for(arg)
  if value.is_a?(Array)
    value.zip(arg).map { |l, r| l.binding_for(r) }.compact
  else
    nil
  end
end

#satisfies?(arg) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/erlectricity/conditions/static.rb', line 14

def satisfies?(arg)
  if value.is_a?(Array)
    return false unless arg.is_a?(Array)
    return false if value.length != arg.length
    value.zip(arg).all? do |l, r|
      l.respond_to?(:satisfies?) ? l.satisfies?(r) : l.eql?(r)
    end
  else
    arg.eql?(value)
  end
end