Class: Kramdown::PlantUml::PlantUmlResult

Inherits:
Object
  • Object
show all
Defined in:
lib/kramdown-plantuml/plantuml_result.rb

Overview

Executes the PlantUML Java application.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plantuml_diagram, stdout, stderr, exitcode) ⇒ PlantUmlResult

Returns a new instance of PlantUmlResult.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kramdown-plantuml/plantuml_result.rb', line 13

def initialize(plantuml_diagram, stdout, stderr, exitcode)
  raise ArgumentError, 'diagram cannot be nil' if plantuml_diagram.nil?
  raise ArgumentError, "diagram must be a #{PlantUmlDiagram}" unless plantuml_diagram.is_a?(PlantUmlDiagram)
  raise ArgumentError, 'exitcode cannot be nil' if exitcode.nil?
  raise ArgumentError, "exitcode must be a #{Integer}" unless exitcode.is_a?(Integer)

  @plantuml_diagram = plantuml_diagram
  @stdout = stdout
  @stderr = stderr
  @exitcode = exitcode
  @logger = LogWrapper.init
end

Instance Attribute Details

#exitcodeObject (readonly)

Returns the value of attribute exitcode.



11
12
13
# File 'lib/kramdown-plantuml/plantuml_result.rb', line 11

def exitcode
  @exitcode
end

#plantuml_diagramObject (readonly)

Returns the value of attribute plantuml_diagram.



11
12
13
# File 'lib/kramdown-plantuml/plantuml_result.rb', line 11

def plantuml_diagram
  @plantuml_diagram
end

#stderrObject (readonly)

Returns the value of attribute stderr.



11
12
13
# File 'lib/kramdown-plantuml/plantuml_result.rb', line 11

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



11
12
13
# File 'lib/kramdown-plantuml/plantuml_result.rb', line 11

def stdout
  @stdout
end

Instance Method Details

#svg_diagramObject



26
27
28
# File 'lib/kramdown-plantuml/plantuml_result.rb', line 26

def svg_diagram
  @plantuml_diagram.svg
end

#valid?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
# File 'lib/kramdown-plantuml/plantuml_result.rb', line 30

def valid?
  return true if @exitcode.zero? || @stderr.nil? || @stderr.empty?

  # If stderr is not empty, but contains the string 'CoreText note:',
  # the error is caused by a bug in Java, and should be ignored.
  # Circumvents https://bugs.openjdk.java.net/browse/JDK-8244621
  @stderr.include?('CoreText note:')
end

#validate!Object

Raises:



39
40
41
42
43
44
45
46
# File 'lib/kramdown-plantuml/plantuml_result.rb', line 39

def validate!
  raise PlantUmlError, self unless valid?

  return if @stderr.nil? || @stderr.empty?

  @logger.debug 'PlantUML log:'
  @logger.debug_multiline @stderr
end