Class: StrongJSON::Type::Array
- Inherits:
-
Object
- Object
- StrongJSON::Type::Array
- Includes:
- Match
- Defined in:
- lib/strong_json/type.rb
Instance Method Summary collapse
- #coerce(value, path: []) ⇒ Object
-
#initialize(type) ⇒ Array
constructor
A new instance of Array.
- #to_s ⇒ Object
Methods included from Match
Constructor Details
#initialize(type) ⇒ Array
Returns a new instance of Array.
111 112 113 |
# File 'lib/strong_json/type.rb', line 111 def initialize(type) @type = type end |
Instance Method Details
#coerce(value, path: []) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/strong_json/type.rb', line 115 def coerce(value, path: []) if value.is_a?(::Array) value.map.with_index do |v, i| @type.coerce(v, path: path+[i]) end else raise Error.new(path: path, type: self, value: value) end end |
#to_s ⇒ Object
125 126 127 |
# File 'lib/strong_json/type.rb', line 125 def to_s "array(#{@type})" end |