lib/erlectricity/conditions/static.rb in mojombo-erlectricity-0.2.1 vs lib/erlectricity/conditions/static.rb in mojombo-erlectricity-1.0.0
- old
+ new
@@ -1,13 +1,34 @@
module Erlectricity
-class StaticCondition < Condition
- attr_accessor :value
- def initialize(value)
- self.value = value
- end
-
- def satisfies?(arg)
- arg.eql? value
- end
+ class StaticCondition < Condition
+ attr_accessor :value
+ def initialize(value)
+ if value.is_a?(Array)
+ self.value = value.map do |v|
+ Condition.for(v)
+ end
+ else
+ self.value = value
+ end
+ end
+ 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
+
+ def binding_for(arg)
+ if value.is_a?(Array)
+ value.zip(arg).map { |l, r| l.binding_for(r) }.compact
+ else
+ nil
+ end
+ end
+ end
end
-end
\ No newline at end of file