Class: Archimate::FileFormats::ArchiFileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/archimate/file_formats/archi_file_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ ArchiFileReader

Returns a new instance of ArchiFileReader.



8
9
10
# File 'lib/archimate/file_formats/archi_file_reader.rb', line 8

def initialize(doc)
  @string_or_io = doc
end

Instance Method Details

#parseObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/archimate/file_formats/archi_file_reader.rb', line 12

def parse
  handler_factory = Sax::Archi::ArchiHandlerFactory.new
  parser = Nokogiri::XML::SAX::Parser.new(Sax::Document.new(handler_factory))
  parser.parse(@string_or_io)
  model = parser.document.model
  model
    .diagrams
    .flat_map(&:connections)
    .each do |connection|
      connection.bendpoints.each do |bendpoint|
        bendpoint.x += connection.start_location.x.to_i
        bendpoint.y += connection.start_location.y.to_i
      end
    end
  model
end