Class: SvgConform::ImageQualityAnalyzer
- Inherits:
-
Object
- Object
- SvgConform::ImageQualityAnalyzer
- Defined in:
- lib/svg_conform/image_quality_analyzer.rb
Overview
Analyzes SVG image quality across multiple dimensions.
Main entry point for quality analysis. Analyzes files and returns immutable QualityResult value objects that can be serialized or rendered.
Instance Method Summary collapse
-
#analyze(path, profile: :svg_1_2_rfc) ⇒ QualityMetrics::QualityResult
Analyze a single SVG file.
-
#analyze_batch(dir, pattern: "**/*.svg", profile: :svg_1_2_rfc, progress: false) ⇒ SvgQualityBatchReport
Analyze all SVG files in a directory.
-
#analyze_report(path, profile: :svg_1_2_rfc) ⇒ SvgQualityReport
Analyze a single SVG file and return report for terminal output.
-
#analyze_reports(dir, pattern: "**/*.svg", profile: :svg_1_2_rfc, progress: false) ⇒ Array<SvgQualityReport>
Analyze all SVG files and return array of reports.
-
#generate_report(results, format: :csv) ⇒ String
Generate a formatted report from results.
-
#initialize(config: nil) ⇒ ImageQualityAnalyzer
constructor
A new instance of ImageQualityAnalyzer.
Constructor Details
#initialize(config: nil) ⇒ ImageQualityAnalyzer
Returns a new instance of ImageQualityAnalyzer.
47 48 49 50 51 52 53 54 55 |
# File 'lib/svg_conform/image_quality_analyzer.rb', line 47 def initialize(config: nil) @config = config || QualityMetrics::Configuration.default @validator = Validator.new @error_analyzer = QualityMetrics::ErrorAnalyzer.new(@config) @feature_detector = QualityMetrics::FeatureDetector.new(@config) @complexity_calculator = QualityMetrics::ComplexityCalculator.new(@config) @quality_calculator = QualityMetrics::QualityCalculator.new(@config) @formatter = QualityMetrics::QualityReportFormatter.new end |
Instance Method Details
#analyze(path, profile: :svg_1_2_rfc) ⇒ QualityMetrics::QualityResult
Analyze a single SVG file.
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 |
# File 'lib/svg_conform/image_quality_analyzer.rb', line 67 def analyze(path, profile: :svg_1_2_rfc) raise ArgumentError, "File not found: #{path}" unless File.exist?(path) file_size_bytes = File.size(path) content = File.read(path) # Run validation validation_result = @validator.validate(content, profile: profile) # Analyze errors error_breakdown = @error_analyzer.analyze(validation_result) # Detect features from content feature_flags = @feature_detector.detect(content) # Calculate complexity complexity_metrics = @complexity_calculator.calculate_from_content( content: content, features: feature_flags, ) # Calculate all quality metrics @quality_calculator.calculate_all( validation_result: validation_result, file_path: path, file_size_bytes: file_size_bytes, error_breakdown: error_breakdown, complexity_metrics: complexity_metrics, feature_flags: feature_flags, ) end |
#analyze_batch(dir, pattern: "**/*.svg", profile: :svg_1_2_rfc, progress: false) ⇒ SvgQualityBatchReport
Analyze all SVG files in a directory.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/svg_conform/image_quality_analyzer.rb', line 121 def analyze_batch(dir, pattern: "**/*.svg", profile: :svg_1_2_rfc, progress: false) reports = analyze_reports(dir, pattern: pattern, profile: profile, progress: progress) summary = summarize_reports(reports) SvgQualityBatchReport.new( total_files: summary[:total_files], successful: summary[:successful], failed: summary[:failed], avg_quality_score: summary[:avg_quality_score], quality_distribution: summary[:quality_distribution], avg_error_count: summary[:avg_error_count], total_errors: summary[:total_errors], remediable_errors: summary[:remediable_errors], non_remediable_errors: summary[:non_remediable_errors], reports: reports, ) end |
#analyze_report(path, profile: :svg_1_2_rfc) ⇒ SvgQualityReport
Analyze a single SVG file and return report for terminal output.
104 105 106 |
# File 'lib/svg_conform/image_quality_analyzer.rb', line 104 def analyze_report(path, profile: :svg_1_2_rfc) analyze(path, profile: profile).to_report end |
#analyze_reports(dir, pattern: "**/*.svg", profile: :svg_1_2_rfc, progress: false) ⇒ Array<SvgQualityReport>
Analyze all SVG files and return array of reports.
148 149 150 151 152 153 154 155 156 |
# File 'lib/svg_conform/image_quality_analyzer.rb', line 148 def analyze_reports(dir, pattern: "**/*.svg", profile: :svg_1_2_rfc, progress: false) files = glob_files(dir, pattern) reports = files.map { |file| analyze_report(file, profile: profile) } puts "Processed #{files.size} files..." if progress && !files.empty? reports rescue StandardError [] end |
#generate_report(results, format: :csv) ⇒ String
Generate a formatted report from results.
163 164 165 166 167 168 169 |
# File 'lib/svg_conform/image_quality_analyzer.rb', line 163 def generate_report(results, format: :csv) case format when :csv then @formatter.format_csv(results) when :json then @formatter.format_json(results) else raise ArgumentError, "Unknown format: #{format}. Use :csv or :json" end end |