Class: Hako::Schema::OrderedArray

Inherits:
Object
  • Object
show all
Defined in:
lib/hako/schema/ordered_array.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ OrderedArray

Returns a new instance of OrderedArray.



6
7
8
# File 'lib/hako/schema/ordered_array.rb', line 6

def initialize(schema)
  @schema = schema
end

Instance Method Details

#same?(xs, ys) ⇒ Boolean

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hako/schema/ordered_array.rb', line 14

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

  xs.zip(ys) do |x, y|
    unless @schema.same?(x, y)
      return false
    end
  end
  true
end

#valid?(object) ⇒ Boolean

Returns:



10
11
12
# File 'lib/hako/schema/ordered_array.rb', line 10

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