Sha256: ca4e44f49bda298f75b7bbf65c44ba1a5a96b1db2235f0648109384ccf00b4a6

Contents?: true

Size: 1.05 KB

Versions: 19

Compression:

Stored size: 1.05 KB

Contents

module Finitio
  module RelBasedType

    def representator
      [tuple_type.representator]
    end

    def include?(value)
      value.is_a?(Set) && value.all?{|tuple|
        tuple_type.include?(tuple)
      }
    end

    # 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.
    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

  private

    def tuple_type
      @tuple_type ||= begin
        clazz = heading.multi? ? MultiTupleType : TupleType
        clazz.new(heading)
      end
    end

  end # module RelBasedType
end # module Finitio

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
finitio-0.12.0 lib/finitio/type/rel_based_type.rb
finitio-0.11.4 lib/finitio/type/rel_based_type.rb
finitio-0.11.3 lib/finitio/type/rel_based_type.rb
finitio-0.11.2 lib/finitio/type/rel_based_type.rb
finitio-0.11.1 lib/finitio/type/rel_based_type.rb
finitio-0.10.0 lib/finitio/type/rel_based_type.rb
finitio-0.9.1 lib/finitio/type/rel_based_type.rb
finitio-0.9.0 lib/finitio/type/rel_based_type.rb
finitio-0.8.0 lib/finitio/type/rel_based_type.rb
finitio-0.7.0 lib/finitio/type/rel_based_type.rb
finitio-0.7.0.pre.rc4 lib/finitio/type/rel_based_type.rb
finitio-0.7.0.pre.rc3 lib/finitio/type/rel_based_type.rb
finitio-0.7.0.pre.rc2 lib/finitio/type/rel_based_type.rb
finitio-0.7.0.pre.rc1 lib/finitio/type/rel_based_type.rb
finitio-0.6.1 lib/finitio/type/rel_based_type.rb
finitio-0.6.0 lib/finitio/type/rel_based_type.rb
finitio-0.5.2 lib/finitio/type/rel_based_type.rb
finitio-0.5.1 lib/finitio/type/rel_based_type.rb
finitio-0.5.0 lib/finitio/type/rel_based_type.rb