Class: JDDF::Discriminator

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

Overview

A JDDF schema discriminator object.

This class is a Struct. It is primarily a helper sub-structure of Schema.

The attributes of this struct are in DISCRIMINATOR_KEYWORDS.

Class Method Summary collapse

Class Method Details

.from_json(hash) ⇒ Object

Construct a JDDF::Discriminator from parsed JSON.

This is primarily meant to be a helper method to Schema.from_json.

Raises:

  • (TypeError)

278
279
280
281
282
283
284
285
286
287
# File 'lib/jddf/schema.rb', line 278

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