Class: Lutaml::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/parser.rb

Constant Summary collapse

EXPRESS_CACHE_PARSE_TYPE =
"exp.cache"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_list, input_type) ⇒ Parser

Returns a new instance of Parser.



24
25
26
27
# File 'lib/lutaml/parser.rb', line 24

def initialize(file_list, input_type)
  @parse_type = input_type || File.extname(file_list.first.path)[1..]
  @file_list = file_list
end

Instance Attribute Details

#file_listObject (readonly)

Returns the value of attribute file_list.



14
15
16
# File 'lib/lutaml/parser.rb', line 14

def file_list
  @file_list
end

#parse_typeObject (readonly)

Returns the value of attribute parse_type.



14
15
16
# File 'lib/lutaml/parser.rb', line 14

def parse_type
  @parse_type
end

Class Method Details

.parse(file_list, input_type = nil) ⇒ Object Also known as: parse_into_document



17
18
19
20
# File 'lib/lutaml/parser.rb', line 17

def parse(file_list, input_type = nil)
  file_list = [file_list] unless file_list.is_a?(Array)
  new(Array(file_list), input_type).parse_into_document
end

Instance Method Details

#parse_into_documentObject

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lutaml/parser.rb', line 29

def parse_into_document # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  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 "qea"
    # QEA files: Direct database parsing for Enterprise Architect
    # Parse single QEA file and return as array for consistency with XMI
    document = Lutaml::Qea.parse(file_list.first.path)
    [document]
  when "xmi"
    file_list.map { |file| Lutaml::Xmi::Parsers::Xml.parse(file) }
  when "xml"
    file_list.map { |file| Lutaml::Xml::Parsers::Xml.parse(file) }
  when "lutaml"
    file_list.map { |file| Lutaml::Uml::Parsers::Dsl.parse(file) }
  when "yml", "yaml"
    file_list.map { |file| Lutaml::Uml::Parsers::Yaml.parse(file.path) }
  else
    raise ArgumentError, "Unsupported file format"
  end
end