Sha256: 438eec6fb021ac2c1da260433b5e10ed9ce28a90d99311bed3bcd114ab9cf86c

Contents?: true

Size: 712 Bytes

Versions: 13

Compression:

Stored size: 712 Bytes

Contents

# frozen_string_literal: true
module Hako
  module Schema
    class Table
      def initialize(key_schema, val_schema)
        @key_schema = key_schema
        @val_schema = val_schema
      end

      def valid?(object)
        object.is_a?(::Hash) && object.all? { |k, v| @key_schema.valid?(k) && @val_schema.valid?(v) }
      end

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

        t = xs.dup
        ys.each do |yk, yv|
          xk, = xs.find { |k, v| @key_schema.same?(k, yk) && @val_schema.same?(v, yv) }
          if xk
            t.delete(xk)
          else
            return false
          end
        end

        t.empty?
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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