Class: Lutaml::Ea::Diagram::Extractor
- Inherits:
-
Object
- Object
- Lutaml::Ea::Diagram::Extractor
- Defined in:
- lib/lutaml/ea/diagram/extractor.rb
Overview
API for extracting and rendering UML diagrams from repositories
This class provides programmatic access to diagram extraction and rendering functionality. It follows API-first architecture, with all business logic in this class rather than in CLI layer.
Constant Summary collapse
- DEFAULT_OPTIONS =
Default rendering options
{ format: "svg", padding: 20, background_color: "#ffffff", grid_visible: false, interactive: false, config_path: nil, }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#extract_batch(lur_path, diagram_ids, opts = {}) ⇒ Hash
Extract multiple diagrams in batch.
-
#extract_one(lur_path, diagram_id, opts = {}) ⇒ Hash
Extract and render a single diagram.
-
#initialize(options = {}) ⇒ Extractor
constructor
Initialize extractor with options.
-
#list_diagrams(lur_path) ⇒ Hash
List all diagrams in repository.
Constructor Details
#initialize(options = {}) ⇒ Extractor
Initialize extractor with options
53 54 55 |
# File 'lib/lutaml/ea/diagram/extractor.rb', line 53 def initialize( = {}) @options = () end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
43 44 45 |
# File 'lib/lutaml/ea/diagram/extractor.rb', line 43 def @options end |
Instance Method Details
#extract_batch(lur_path, diagram_ids, opts = {}) ⇒ Hash
Extract multiple diagrams in batch
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/lutaml/ea/diagram/extractor.rb', line 142 def extract_batch(lur_path, diagram_ids, opts = {}) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength merged_opts = @options.merge(opts) output_dir = merged_opts[:output_dir] || "." # Create output directory if needed FileUtils.mkdir_p(output_dir) results = diagram_ids.map do |diagram_id| output_path = File.join(output_dir, "#{sanitize_filename(diagram_id)}.svg") extract_one(lur_path, diagram_id, merged_opts.merge(output: output_path)) end successful = results.count { |r| r[:success] } failed = results.count { |r| !r[:success] } { success: failed.zero?, results: results, summary: { total: diagram_ids.size, successful: successful, failed: failed, }, } rescue StandardError => e { success: false, message: "Batch extraction failed: #{e.}", error: e, } end |
#extract_one(lur_path, diagram_id, opts = {}) ⇒ Hash
Extract and render a single diagram
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/lutaml/ea/diagram/extractor.rb', line 64 def extract_one(lur_path, diagram_id, opts = {}) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength merged_opts = @options.merge(opts) # Load repository repository = load_repository(lur_path) # Find diagram diagram = find_diagram(repository, diagram_id) unless diagram return { success: false, message: "Diagram not found: #{diagram_id}", available: repository.all_diagrams.map(&:name), } end # Convert to rendering format diagram_data = convert_to_rendering_format(diagram, repository) # Render svg_content = render_diagram(diagram_data, merged_opts) # Determine output path output_path = merged_opts[:output] # Write file if output path specified File.write(output_path, svg_content) if output_path result = { success: true, diagram: diagram_info(diagram), format: merged_opts[:format], message: "Diagram rendered successfully", } # Include path if file was written result[:path] = output_path if output_path # Include SVG content if no output file (for testing) result[:svg_content] = svg_content unless output_path result rescue StandardError => e { success: false, message: "Failed to extract diagram: #{e.}", error: e, } end |
#list_diagrams(lur_path) ⇒ Hash
List all diagrams in repository
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/lutaml/ea/diagram/extractor.rb', line 118 def list_diagrams(lur_path) # rubocop:disable Metrics/MethodLength repository = load_repository(lur_path) diagrams = repository.all_diagrams { success: true, count: diagrams.size, diagrams: diagrams.map { |d| diagram_info(d) }, } rescue StandardError => e { success: false, message: "Failed to list diagrams: #{e.}", error: e, } end |