Sha256: cce32e67685d81c91ab26dd4cf748964833a1fe305b88be4ac697232b74d41ec

Contents?: true

Size: 586 Bytes

Versions: 50

Compression:

Stored size: 586 Bytes

Contents

# frozen_string_literal: true

module Hako
  module Schema
    class UnorderedArray
      def initialize(schema)
        @schema = schema
      end

      def valid?(object)
        object.is_a?(Array) && object.all? { |e| @schema.valid?(e) }
      end

      def same?(xs, ys)
        if xs.size != ys.size
          return false
        end

        t = xs.dup
        ys.each do |y|
          i = t.index { |x| @schema.same?(x, y) }
          if i
            t.delete_at(i)
          else
            return false
          end
        end

        true
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
hako-2.17.0 lib/hako/schema/unordered_array.rb
hako-2.16.0 lib/hako/schema/unordered_array.rb
hako-2.15.1 lib/hako/schema/unordered_array.rb
hako-2.15.0 lib/hako/schema/unordered_array.rb
hako-2.14.0 lib/hako/schema/unordered_array.rb
hako-2.13.0 lib/hako/schema/unordered_array.rb
hako-2.12.0 lib/hako/schema/unordered_array.rb
hako-2.11.1 lib/hako/schema/unordered_array.rb
hako-2.11.0 lib/hako/schema/unordered_array.rb
hako-2.10.0 lib/hako/schema/unordered_array.rb
hako-2.9.2 lib/hako/schema/unordered_array.rb
hako-2.9.1 lib/hako/schema/unordered_array.rb
hako-2.9.0 lib/hako/schema/unordered_array.rb
hako-2.8.0 lib/hako/schema/unordered_array.rb
hako-2.7.0 lib/hako/schema/unordered_array.rb
hako-2.6.2 lib/hako/schema/unordered_array.rb
hako-2.6.1 lib/hako/schema/unordered_array.rb
hako-2.6.0 lib/hako/schema/unordered_array.rb
hako-2.5.1 lib/hako/schema/unordered_array.rb
hako-2.5.0 lib/hako/schema/unordered_array.rb