Class: Hako::Schema::UnorderedArray
- Inherits:
-
Object
- Object
- Hako::Schema::UnorderedArray
- Defined in:
- lib/hako/schema/unordered_array.rb
Instance Method Summary collapse
-
#initialize(schema) ⇒ UnorderedArray
constructor
A new instance of UnorderedArray.
- #same?(xs, ys) ⇒ Boolean
- #valid?(object) ⇒ Boolean
Constructor Details
#initialize(schema) ⇒ UnorderedArray
Returns a new instance of UnorderedArray.
6 7 8 |
# File 'lib/hako/schema/unordered_array.rb', line 6 def initialize(schema) @schema = schema end |
Instance Method Details
#same?(xs, ys) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hako/schema/unordered_array.rb', line 14 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 |
#valid?(object) ⇒ Boolean
10 11 12 |
# File 'lib/hako/schema/unordered_array.rb', line 10 def valid?(object) object.is_a?(Array) && object.all? { |e| @schema.valid?(e) } end |