lib/key_vortex/limitation.rb in key-vortex-0.1.4 vs lib/key_vortex/limitation.rb in key-vortex-0.2.0
- old
+ new
@@ -18,29 +18,41 @@
end
@constraints += constraints
end
- def allows?(limitation)
+ def encompasses?(limitation)
@constraints.all? do |constraint|
- limitation.accomodates?(constraint)
+ limitation.encompasses_constraint?(constraint)
end
end
- def prohibits?(limitation)
- !allows?(limitation)
+ def encompasses_constraint?(constraint)
+ !applicable_constraints(constraint).select do |con|
+ con.within?(constraint)
+ end.empty?
end
- def applicable_constraints(constraint)
- @constraints.select do |con|
- con.applies_to?(constraint)
+ def within?(limitation)
+ limitation.constraints.all? do |constraint|
+ within_constraint?(constraint)
end
end
- def accomodates?(constraint)
+ def within_constraint?(constraint)
!applicable_constraints(constraint).select do |con|
con.within?(constraint)
end.empty?
+ end
+
+ def applicable_constraints(constraint)
+ @constraints.select do |con|
+ con.applies_to?(constraint)
+ end
+ end
+
+ def accepts?(value)
+ value.is_a?(type) && @constraints.all? { |constraint| constraint.accepts?(value) }
end
def to_s
"Limitation: #{@type}\n\t#{@constraints.join('\n\t')}"
end