Class: Lutaml::Parser
- Inherits:
-
Object
- Object
- Lutaml::Parser
- Defined in:
- lib/lutaml/parser.rb
Constant Summary collapse
- EXPRESS_CACHE_PARSE_TYPE =
"exp.cache".freeze
Instance Attribute Summary collapse
-
#file_list ⇒ Object
readonly
Returns the value of attribute file_list.
-
#parse_type ⇒ Object
readonly
Returns the value of attribute parse_type.
Class Method Summary collapse
- .parse(file_list, input_type = nil) ⇒ Object
- .parse_into_document(file_list, input_type = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(file_list, input_type) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #parse_into_document ⇒ Object
Constructor Details
#initialize(file_list, input_type) ⇒ Parser
Returns a new instance of Parser.
26 27 28 29 |
# File 'lib/lutaml/parser.rb', line 26 def initialize(file_list, input_type) @parse_type = input_type || File.extname(file_list.first.path)[1..-1] @file_list = file_list end |
Instance Attribute Details
#file_list ⇒ Object (readonly)
Returns the value of attribute file_list.
12 13 14 |
# File 'lib/lutaml/parser.rb', line 12 def file_list @file_list end |
#parse_type ⇒ Object (readonly)
Returns the value of attribute parse_type.
12 13 14 |
# File 'lib/lutaml/parser.rb', line 12 def parse_type @parse_type end |
Class Method Details
.parse(file_list, input_type = nil) ⇒ Object
15 16 17 18 |
# File 'lib/lutaml/parser.rb', line 15 def parse(file_list, input_type = nil) file_list = file_list.is_a?(Array) ? file_list : [file_list] new(Array(file_list), input_type).parse end |
.parse_into_document(file_list, input_type = nil) ⇒ Object
20 21 22 23 |
# File 'lib/lutaml/parser.rb', line 20 def parse_into_document(file_list, input_type = nil) file_list = file_list.is_a?(Array) ? file_list : [file_list] new(Array(file_list), input_type).parse_into_document end |
Instance Method Details
#parse ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/lutaml/parser.rb', line 31 def parse documents = parse_into_document return document_wrapper(documents) if ["exp", EXPRESS_CACHE_PARSE_TYPE].include?(parse_type) documents.map { |doc| document_wrapper(doc) } end |
#parse_into_document ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lutaml/parser.rb', line 39 def parse_into_document case parse_type when "exp" Expressir::Express::Parser.from_files(file_list.map(&:path)) when EXPRESS_CACHE_PARSE_TYPE Expressir::Express::Cache.from_file(file_list.first.path) when "xmi" file_list.map { |file| Lutaml::XMI::Parsers::XML.parse(file) } when "lutaml" file_list.map { |file| Lutaml::Uml::Parsers::Dsl.parse(file) } when "yml" file_list.map { |file| Lutaml::Uml::Parsers::Yaml.parse(file.path) } else raise ArgumentError, "Unsupported file format" end end |