Class: Lutaml::Lml::DocumentBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/lml/document_builder.rb

Constant Summary collapse

DEFAULT_REGISTRY =

Default registry: builder keys → LML model classes. Callers needing a different mapping can pass their own registry to ‘new`; this constant documents the default composition.

{
  document: ::Lutaml::Lml::Document,
  package: ::Lutaml::Lml::Package,
  class: ::Lutaml::Lml::UmlClass,
  enum: ::Lutaml::Lml::Enum,
  data_type: ::Lutaml::Lml::DataType,
  diagram: ::Lutaml::Lml::Diagram,
  attribute: ::Lutaml::Lml::TopElementAttribute,
  cardinality: ::Lutaml::Lml::Cardinality,
  association: ::Lutaml::Lml::Association,
  operation: ::Lutaml::Lml::Operation,
  constraint: ::Lutaml::Lml::Constraint,
  value: ::Lutaml::Lml::Value,
  view_import: ::Lutaml::Lml::ViewImport,
  view_filter: ::Lutaml::Lml::ViewFilter
}.freeze
FACTORY_KEYS =
%i[
  document package class enum data_type diagram view_import view_filter
  attribute association operation constraint value cardinality
].freeze
MEMBER_KEY_MAP =
{
  packages: :package,
  classes: :class,
  enums: :enum,
  data_types: :data_type,
  diagrams: :diagram,
  view_imports: :view_import,
  attributes: :attribute,
  associations: :association,
  operations: :operation,
  constraints: :constraint,
  values: :value
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry = DEFAULT_REGISTRY) ⇒ DocumentBuilder

Returns a new instance of DocumentBuilder.



28
29
30
# File 'lib/lutaml/lml/document_builder.rb', line 28

def initialize(registry = DEFAULT_REGISTRY)
  @registry = registry
end

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



26
27
28
# File 'lib/lutaml/lml/document_builder.rb', line 26

def registry
  @registry
end

Instance Method Details

#build(key, hash) ⇒ Object



55
56
57
# File 'lib/lutaml/lml/document_builder.rb', line 55

def build(key, hash)
  @registry.fetch(key).new.tap { |model| set_model(model, hash) }
end