Class: DrawUml::Diagram

Inherits:
Object
  • Object
show all
Defined in:
lib/draw_uml/diagram.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Diagram

Returns a new instance of Diagram.



5
6
7
8
# File 'lib/draw_uml/diagram.rb', line 5

def initialize(path)
  @path = path
  FileUtils.mkdir_p(@path)
end

Instance Method Details

#create(source_path, dest_path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/draw_uml/diagram.rb', line 10

def create(source_path, dest_path)
  raw = File.read(source_path)
  digest = Digest::MD5.hexdigest(raw)

  tmp_file = File.join(@path, dest_path + ".#{digest}.tmp")
  unless File.exist?(tmp_file)
    png_file = File.join(@path, dest_path + '.png')
    FileUtils.mkdir_p(File.dirname(png_file))

    cmd = 'plantuml -pipe > ' + png_file
    stdout, status = Open3.capture2(cmd, stdin_data: raw)

    files = Dir[File.join(@path, dest_path + ".*.tmp")]
    File.unlink(*files)
    File.write(tmp_file, nil)
  end
end