Class: Jsapi::JSON::Array
Overview
Represents a JSON array.
Instance Attribute Summary
Attributes inherited from Value
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Returns true if it contains no elements, false otherwise.
-
#initialize(array, schema, definitions, context: nil) ⇒ Array
constructor
A new instance of Array.
-
#inspect ⇒ Object
:nodoc:.
-
#validate(errors) ⇒ Object
:nodoc:.
- #value ⇒ Object
Methods inherited from Value
Constructor Details
#initialize(array, schema, definitions, context: nil) ⇒ Array
Returns a new instance of Array.
7 8 9 10 11 12 |
# File 'lib/jsapi/json/array.rb', line 7 def initialize(array, schema, definitions, context: nil) super(schema) @json_values = Array(array).map do |item| JSON.wrap(item, schema.items, definitions, context: context) end end |
Instance Method Details
#empty? ⇒ Boolean
Returns true if it contains no elements, false otherwise.
15 16 17 |
# File 'lib/jsapi/json/array.rb', line 15 def empty? @json_values.empty? end |
#inspect ⇒ Object
:nodoc:
19 20 21 |
# File 'lib/jsapi/json/array.rb', line 19 def inspect # :nodoc: "#<#{self.class.name} [#{@json_values.map(&:inspect).join(', ')}]>" end |
#validate(errors) ⇒ Object
:nodoc:
23 24 25 26 27 |
# File 'lib/jsapi/json/array.rb', line 23 def validate(errors) # :nodoc: return false unless super @json_values.map { |element| element.validate(errors) }.all? end |
#value ⇒ Object
29 30 31 |
# File 'lib/jsapi/json/array.rb', line 29 def value @value ||= @json_values.map(&:value) end |