Class: Lutaml::Model::Schema::RngCompiler::ValueTypeResolver
- Inherits:
-
Object
- Object
- Lutaml::Model::Schema::RngCompiler::ValueTypeResolver
- Defined in:
- lib/lutaml/model/schema/rng_compiler/value_type_resolver.rb
Overview
Resolves the value-shape of an element or attribute container into a Symbol (built-in / registered type) or nil if the container has structural content needing its own class.
Patterns handled:
<element><text/></element> -> :string
<element><data type="X"/></element> -> mapped primitive
<element><data ...><param ...>/></data></element> -> anonymous RestrictedType (returns its registry symbol)
<element><choice><value>...</value></choice></element> -> anonymous RestrictedType (enum) (returns its registry symbol)
<element><ref name="StFoo"/></element> -> :st_foo (if simple)
When an anonymous RestrictedType is needed, the resolver builds it
(pure) and asks the supplied register_class callback to register
it. Build and register are separate methods so unit testing can
exercise the pure logic without side effects.
Instance Method Summary collapse
-
#initialize(defines, classes, compile_define:, register_class:) ⇒ ValueTypeResolver
constructor
A new instance of ValueTypeResolver.
-
#resolve(container) ⇒ Object
Returns the resolved type symbol, or nil if
containerneeds its own class.
Constructor Details
#initialize(defines, classes, compile_define:, register_class:) ⇒ ValueTypeResolver
Returns a new instance of ValueTypeResolver.
23 24 25 26 27 28 |
# File 'lib/lutaml/model/schema/rng_compiler/value_type_resolver.rb', line 23 def initialize(defines, classes, compile_define:, register_class:) @defines = defines @classes = classes @compile_define = compile_define @register_class = register_class end |
Instance Method Details
#resolve(container) ⇒ Object
Returns the resolved type symbol, or nil if container needs
its own class. May register an anonymous RestrictedType as a
side effect (delegated to the register_class callback).
33 34 35 36 37 |
# File 'lib/lutaml/model/schema/rng_compiler/value_type_resolver.rb', line 33 def resolve(container) return nil if RngHelpers.branching_structural?(container) type_from_inline_simple(container) || primitive_or_ref(container) end |