Class: Structure::Type::ArrayWithStruct
- Defined in:
- lib/structure.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#struct ⇒ Object
readonly
Returns the value of attribute struct.
Attributes inherited from Single
Instance Method Summary collapse
- #exactly(number) ⇒ Object
-
#initialize(struct) ⇒ ArrayWithStruct
constructor
A new instance of ArrayWithStruct.
- #matches?(json) ⇒ Boolean
- #times ⇒ Object
Methods inherited from Array
#at_least, #between, #elements, #elements_at_least, #elements_at_most, #inspect, #items, #with
Methods inherited from Single
Constructor Details
#initialize(struct) ⇒ ArrayWithStruct
Returns a new instance of ArrayWithStruct.
111 112 113 114 115 116 |
# File 'lib/structure.rb', line 111 def initialize(struct) super([]) @struct = struct @max = 999_999 @min = 1 end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
109 110 111 |
# File 'lib/structure.rb', line 109 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
109 110 111 |
# File 'lib/structure.rb', line 109 def min @min end |
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
109 110 111 |
# File 'lib/structure.rb', line 109 def struct @struct end |
Instance Method Details
#exactly(number) ⇒ Object
118 119 120 |
# File 'lib/structure.rb', line 118 def exactly(number) with(number) end |
#matches?(json) ⇒ Boolean
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/structure.rb', line 126 def matches?(json) result = json.count do |j| yield @struct, j rescue Structure::Type::Error false end raise MatchError, "#{json}\n has no #{@struct}" unless result && result.between?(@min, @max) true end |
#times ⇒ Object
122 123 124 |
# File 'lib/structure.rb', line 122 def times elements end |