Class: SvgConform::QualityMetrics::FeatureDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/svg_conform/quality_metrics/feature_detector.rb

Overview

Detects SVG features in file content using regex patterns.

Examples:

config = Configuration.default
detector = FeatureDetector.new(config)

features = detector.detect(File.read('image.svg'))
puts features.has_base64?  # => false
puts features.present_features  # => [:masks, :clip_paths]

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ FeatureDetector

Returns a new instance of FeatureDetector.

Parameters:



17
18
19
# File 'lib/svg_conform/quality_metrics/feature_detector.rb', line 17

def initialize(config)
  @config = config
end

Instance Method Details

#detect(content_or_path) ⇒ FeatureFlags

Detect features in content or file

Parameters:

  • content_or_path (String)

    Either raw SVG content or path to file

Returns:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/svg_conform/quality_metrics/feature_detector.rb', line 25

def detect(content_or_path)
  content = read_content(content_or_path)

  FeatureFlags.new(
    has_base64: match_pattern?(:base64, content),
    has_foreign_ns: match_pattern?(:foreign_ns, content),
    has_masks: match_pattern?(:masks, content),
    has_clip_paths: match_pattern?(:clip_paths, content),
    has_external_refs: match_pattern?(:external_refs, content),
  )
end