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.
31 32 33 34 35 |
# File 'lib/lutaml/xml/parsers/xml.rb', line 31 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
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lutaml/xml/parsers/xml.rb', line 13 def self.load_schema(schema, root_schema) result = Shale::Schema.from_xml([schema]) result.values.each do |klass| # Temporary solution will update in the parser klass = klass.gsub(/^require.*?\n/, "") klass = klass.gsub(/< Shale::Mapper/, "< Lutaml::Xml::Mapper") eval(klass, TOPLEVEL_BINDING) end @@root_schema = root_schema end |
.parse(file) ⇒ Object
27 28 29 |
# File 'lib/lutaml/xml/parsers/xml.rb', line 27 def self.parse(file) new(file, @@root_schema).parse end |
Instance Method Details
#parse ⇒ Object
37 38 39 40 41 |
# File 'lib/lutaml/xml/parsers/xml.rb', line 37 def parse doc = File.read(@file) @root_class.from_xml(doc) end |