Class: Structure::Type::Array
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Single
Instance Method Summary collapse
- #at_least(number) ⇒ Object
- #between(min, max) ⇒ Object
- #elements ⇒ Object
- #elements_at_least ⇒ Object
- #elements_at_most ⇒ Object
-
#initialize(classes) ⇒ Array
constructor
A new instance of Array.
- #inspect ⇒ Object
- #items ⇒ Object
- #matches?(json) ⇒ Boolean
- #with(number) ⇒ Object
Methods inherited from Single
Constructor Details
#initialize(classes) ⇒ Array
Returns a new instance of Array.
41 42 43 44 45 |
# File 'lib/structure.rb', line 41 def initialize(classes) super(classes) @max = 999_999 @min = 0 end |
Instance Method Details
#at_least(number) ⇒ Object
53 54 55 |
# File 'lib/structure.rb', line 53 def at_least(number) between(number, Float::INFINITY) end |
#between(min, max) ⇒ Object
47 48 49 50 51 |
# File 'lib/structure.rb', line 47 def between(min, max) @min = min @max = max self end |
#elements ⇒ Object
62 63 64 65 66 |
# File 'lib/structure.rb', line 62 def elements @min = @number @max = @number self end |
#elements_at_least ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/structure.rb', line 80 def elements_at_least raise "Wrong use of at_least" unless @number @min = @number @number = nil self end |
#elements_at_most ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/structure.rb', line 72 def elements_at_most raise "Wrong use of at_most" unless @number @max = @number @number = nil self end |
#inspect ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/structure.rb', line 99 def inspect if class? "a_list_of(#{@classes.inspect})" else "a_list_of(\n#{@classes.pretty_inspect})" end end |
#items ⇒ Object
68 69 70 |
# File 'lib/structure.rb', line 68 def items elements end |
#matches?(json) ⇒ Boolean
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/structure.rb', line 88 def matches?(json) unless json.size.between?( @min, @max ) raise SizeError, "Size Error: #{inspect} size (#{json.size}) is not between #{@min} and #{@max}." end json.all? { |j| classes.any? { |s| yield s, j } } end |
#with(number) ⇒ Object
57 58 59 60 |
# File 'lib/structure.rb', line 57 def with(number) @number = number self end |