Class: Archimate::Cli::Svger
- Inherits:
-
Object
- Object
- Archimate::Cli::Svger
- Defined in:
- lib/archimate/cli/svger.rb
Overview
This class is used to export SVG diagrams as defined in the given model
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #diagram_base_name(diagram, name_option) ⇒ Object
- #export(diagram, file_name = nil) ⇒ Object
- #export_svgs ⇒ Object
-
#filename_for(diagram, name_option) ⇒ Object
TODO: in case of duplicate name in a model, we need to extend the filename with a numeric or something.
-
#initialize(diagrams, output_dir, options = {}) ⇒ Svger
constructor
A new instance of Svger.
Constructor Details
#initialize(diagrams, output_dir, options = {}) ⇒ Svger
Returns a new instance of Svger.
20 21 22 23 24 25 |
# File 'lib/archimate/cli/svger.rb', line 20 def initialize(diagrams, output_dir, = {}) @options = DEFAULT_OPTIONS.merge() @diagrams = diagrams @output_dir = output_dir @diagram_base_names = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/archimate/cli/svger.rb', line 14 def @options end |
Class Method Details
Instance Method Details
#diagram_base_name(diagram, name_option) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/archimate/cli/svger.rb', line 56 def diagram_base_name(diagram, name_option) case name_option when :name diagram.name # when :folder_name # diagram.name # TODO: add the path else diagram.id end end |
#export(diagram, file_name = nil) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/archimate/cli/svger.rb', line 38 def export(diagram, file_name = nil) file_name = Cli.process_svg_filename(file_name || diagram.id) File.open(File.join(@output_dir, file_name), "wb") do |svg_file| svg_file.write(Svg::Diagram.new(diagram, ).to_svg) end end |
#export_svgs ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/archimate/cli/svger.rb', line 27 def export_svgs @diagram_base_names = {} progress = ProgressIndicator.new(total: @diagrams.size, title: "Writing SVGs") @diagrams.each do |diagram| export(diagram, filename_for(diagram, [:svg_name])) progress.increment end ensure progress.finish end |
#filename_for(diagram, name_option) ⇒ Object
TODO: in case of duplicate name in a model, we need to extend the filename with a numeric or something.
46 47 48 49 50 51 52 53 54 |
# File 'lib/archimate/cli/svger.rb', line 46 def filename_for(diagram, name_option) base_name = diagram_base_name(diagram, name_option) if @diagram_base_names.include?(base_name) idx = 2 idx += 1 while @diagram_base_names.include?(base_name + " - #{idx}") base_name += " - #{idx}" end base_name end |