Module: Finitio::RelBasedType
- Included in:
- MultiRelationType, RelationType
- Defined in:
- lib/finitio/type/rel_based_type.rb
Instance Method Summary collapse
-
#dress(value, handler = DressHelper.new) ⇒ Object
Apply the corresponding TupleType’s ‘dress` to every element of `value` (any enumerable).
- #include?(value) ⇒ Boolean
- #representator ⇒ Object
Instance Method Details
#dress(value, handler = DressHelper.new) ⇒ Object
Apply the corresponding TupleType’s ‘dress` to every element of `value` (any enumerable). Return a Set of transformed tuples. Fail if anything goes wrong transforming tuples or if duplicates are found.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/finitio/type/rel_based_type.rb', line 17 def dress(value, handler = DressHelper.new) handler.failed!(self, value) unless value.respond_to?(:each) # Up every tuple and keep results in a Set set = Set.new handler.iterate(value) do |tuple, index| tuple = tuple_type.dress(tuple, handler) handler.fail!("Duplicate tuple") if set.include?(tuple) set << tuple end # Return built tuples set end |
#include?(value) ⇒ Boolean
8 9 10 11 12 |
# File 'lib/finitio/type/rel_based_type.rb', line 8 def include?(value) value.is_a?(Set) && value.all?{|tuple| tuple_type.include?(tuple) } end |
#representator ⇒ Object
4 5 6 |
# File 'lib/finitio/type/rel_based_type.rb', line 4 def representator [tuple_type.representator] end |