Class: MatrixUnion
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- MatrixUnion
- Defined in:
- lib/schema.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 |
# File 'lib/schema.rb', line 1302 def self.from_dynamic!(d) begin value = MatrixClass.from_dynamic!(d) return new(matrix_class: value, union_array: nil) if schema[:matrix_class].right.valid? value rescue StandardError end begin value = d.map { |x| MatrixElement.from_dynamic!(x) } return new(union_array: value, matrix_class: nil) if schema[:union_array].right.valid? value rescue StandardError end raise "Invalid union" end |
.from_json!(json) ⇒ Object
1316 1317 1318 |
# File 'lib/schema.rb', line 1316 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
1320 1321 1322 1323 1324 1325 1326 |
# File 'lib/schema.rb', line 1320 def to_dynamic if !matrix_class.nil? matrix_class.to_dynamic elsif !union_array.nil? union_array.map(&:to_dynamic) end end |
#to_json(options = nil) ⇒ Object
1328 1329 1330 |
# File 'lib/schema.rb', line 1328 def to_json( = nil) JSON.generate(to_dynamic, ) end |