Sha256: 0d7815adf0b383864fe736791f6c1084d367ea640d448ac7e9bf721f943ab9ea

Contents?: true

Size: 585 Bytes

Versions: 13

Compression:

Stored size: 585 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

13 entries across 13 versions & 1 rubygems

Version Path
hako-1.1.0 lib/hako/schema/unordered_array.rb
hako-1.0.1 lib/hako/schema/unordered_array.rb
hako-1.0.0 lib/hako/schema/unordered_array.rb
hako-0.27.0 lib/hako/schema/unordered_array.rb
hako-0.26.0 lib/hako/schema/unordered_array.rb
hako-0.25.2 lib/hako/schema/unordered_array.rb
hako-0.25.1 lib/hako/schema/unordered_array.rb
hako-0.25.0 lib/hako/schema/unordered_array.rb
hako-0.24.0 lib/hako/schema/unordered_array.rb
hako-0.23.0 lib/hako/schema/unordered_array.rb
hako-0.22.0 lib/hako/schema/unordered_array.rb
hako-0.21.1 lib/hako/schema/unordered_array.rb
hako-0.21.0 lib/hako/schema/unordered_array.rb