Class: Lutaml::Xml::Parsers::Xml
- Inherits:
-
Object
- Object
- Lutaml::Xml::Parsers::Xml
- Defined in:
- lib/lutaml/xml/parsers/xml.rb
Overview
Class for parsing .xml schema files into ::Lutaml::Uml::Document
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file, root_schema) ⇒ Xml
constructor
A new instance of Xml.
- #parse ⇒ Object
Constructor Details
#initialize(file, root_schema) ⇒ Xml
Returns a new instance of Xml.
32 33 34 35 36 |
# File 'lib/lutaml/xml/parsers/xml.rb', line 32 def initialize(file, root_schema) @file = file @root_schema = root_schema @root_class = Object.const_get(root_schema) end |
Class Method Details
.load_schema(schema, root_schema) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lutaml/xml/parsers/xml.rb', line 16 def self.load_schema(schema, root_schema) result = Lutaml::Model::Schema.from_xml(schema, module_namespace: nil) result.each_value do |klass| klass = klass.gsub(/^require.*?\n/, "") eval(klass, TOPLEVEL_BINDING) # rubocop:disable Security/Eval end @@root_schema = root_schema end |
.parse(file) ⇒ Object
28 29 30 |
# File 'lib/lutaml/xml/parsers/xml.rb', line 28 def self.parse(file) new(file, @@root_schema).parse end |
Instance Method Details
#parse ⇒ Object
38 39 40 41 42 |
# File 'lib/lutaml/xml/parsers/xml.rb', line 38 def parse doc = File.read(@file) @root_class.from_xml(doc) end |