Class: JDDF::Discriminator

Inherits:
Struct
  • Object
show all
Defined in:
lib/jddf/schema.rb

Class Method Summary collapse

Class Method Details

.from_json(hash) ⇒ Object

Raises:

  • (TypeError)


224
225
226
227
228
229
230
231
232
233
# File 'lib/jddf/schema.rb', line 224

def self.from_json(hash)
  raise TypeError, 'tag not String' unless hash['tag'].is_a?(String)
  raise TypeError, 'mapping not Hash' unless hash['mapping'].is_a?(Hash)

  mapping = hash['mapping'].map do |key, schema|
    [key, Schema.from_json(schema)]
  end.to_h

  Discriminator.new(hash['tag'], mapping)
end