Module: Mml::VersionedParser
Instance Method Summary collapse
-
#parse(input, namespace_exist: true, context: Mml::UNSPECIFIED_CONTEXT, register: nil) ⇒ Object
Shared parse entrypoint for versioned modules.
-
#parse_context_id(context, register) ⇒ Object
Version modules keep their own default context id.
-
#parse_with_no_namespace(input) ⇒ Object
Namespace-less MathML is normalized before handing it to lutaml-model.
-
#xml_input(input, namespace_exist) ⇒ Object
Keep the main parse flow readable by separating namespace normalization.
Instance Method Details
#parse(input, namespace_exist: true, context: Mml::UNSPECIFIED_CONTEXT, register: nil) ⇒ Object
Shared parse entrypoint for versioned modules.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mml/versioned_parser.rb', line 6 def parse(input, namespace_exist: true, context: Mml::UNSPECIFIED_CONTEXT, register: nil) self::Configuration.adapter ||= Mml::DEFAULT_ADAPTER context_id = parse_context_id(context, register) root_class = Lutaml::Model::GlobalContext.resolve_type( :math, context_id, ) root_class.from_xml( xml_input(input, namespace_exist), register: context_id, ) end |
#parse_context_id(context, register) ⇒ Object
Version modules keep their own default context id.
30 31 32 33 34 35 36 37 |
# File 'lib/mml/versioned_parser.rb', line 30 def parse_context_id(context, register) Mml::ContextOptions.normalize_context_option( context: context, register: register, default_context: self::Configuration.default_context_id, warning_source: "#{name}.parse", ) end |
#parse_with_no_namespace(input) ⇒ Object
Namespace-less MathML is normalized before handing it to lutaml-model.
22 23 24 25 26 27 |
# File 'lib/mml/versioned_parser.rb', line 22 def parse_with_no_namespace(input) adapter = self::Configuration.adapter || Mml::DEFAULT_ADAPTER Moxml.new(adapter).parse(input).tap do |doc| doc.root.add_namespace(nil, self::Namespace.uri) end.to_xml end |
#xml_input(input, namespace_exist) ⇒ Object
Keep the main parse flow readable by separating namespace normalization.
40 41 42 43 44 |
# File 'lib/mml/versioned_parser.rb', line 40 def xml_input(input, namespace_exist) return input if namespace_exist parse_with_no_namespace(input) end |