Class: SvgConform::SaxDocument

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

Overview

SAX-based document for streaming validation Provides high-performance validation for large SVG files without loading entire DOM tree into memory

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, file_path = nil) ⇒ SaxDocument

Returns a new instance of SaxDocument.



21
22
23
24
# File 'lib/svg_conform/sax_document.rb', line 21

def initialize(content, file_path = nil)
  @content = content
  @file_path = file_path
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



11
12
13
# File 'lib/svg_conform/sax_document.rb', line 11

def content
  @content
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



11
12
13
# File 'lib/svg_conform/sax_document.rb', line 11

def file_path
  @file_path
end

Class Method Details

.from_content(content) ⇒ Object



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

def self.from_content(content)
  new(content, nil)
end

.from_file(file_path) ⇒ Object



13
14
15
# File 'lib/svg_conform/sax_document.rb', line 13

def self.from_file(file_path)
  new(File.read(file_path), file_path)
end

Instance Method Details

#to_domObject

For compatibility - convert to DOM when needed



42
43
44
# File 'lib/svg_conform/sax_document.rb', line 42

def to_dom
  Document.from_content(@content)
end

#validate_with_profile(profile) ⇒ Object

Validate using SAX streaming parser



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/svg_conform/sax_document.rb', line 27

def validate_with_profile(profile)
  handler = SaxValidationHandler.new(profile)
  parser = Nokogiri::XML::SAX::Parser.new(handler)

  begin
    parser.parse(@content)
  rescue StandardError => e
    # Handle parse errors
    handler.add_parse_error(e)
  end

  handler.result
end