Class: Structure::Type::ArrayWithStruct

Inherits:
Array show all
Defined in:
lib/structure.rb

Instance Attribute Summary collapse

Attributes inherited from Single

#classes

Instance Method Summary collapse

Methods inherited from Array

#at_least, #between, #elements, #elements_at_least, #elements_at_most, #inspect, #items, #with

Methods inherited from Single

#class?, #inspect

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

#maxObject (readonly)

Returns the value of attribute max.



109
110
111
# File 'lib/structure.rb', line 109

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



109
110
111
# File 'lib/structure.rb', line 109

def min
  @min
end

#structObject (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

Returns:

  • (Boolean)

Raises:



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

#timesObject



122
123
124
# File 'lib/structure.rb', line 122

def times
  elements
end