Class: Lutaml::Parser

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

Constant Summary collapse

EXPRESS_CACHE_PARSE_TYPE =
"exp.cache".freeze

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.



27
28
29
30
# File 'lib/lutaml/parser.rb', line 27

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_listObject (readonly)

Returns the value of attribute file_list.



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

def file_list
  @file_list
end

#parse_typeObject (readonly)

Returns the value of attribute parse_type.



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

def parse_type
  @parse_type
end

Class Method Details

.parse(file_list, input_type = nil) ⇒ Object



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

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



21
22
23
24
# File 'lib/lutaml/parser.rb', line 21

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

#parseObject



32
33
34
35
36
37
38
# File 'lib/lutaml/parser.rb', line 32

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_documentObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lutaml/parser.rb', line 40

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 "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"
    file_list.map { |file| Lutaml::Uml::Parsers::Yaml.parse(file.path) }
  else
    raise ArgumentError, "Unsupported file format"
  end
end