Class: SvgConform::Errors::Base

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

Overview

Base class for all SvgConform error types

Provides common interface for error and notice objects used during validation.

Direct Known Subclasses

ValidationIssue, ValidationNotice

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, node:, message:) ⇒ Base

Initialize a new error/notice

Parameters:

  • type (Symbol)

    The type (:error, :warning, :info, etc.)

  • node (Object)

    The node associated with this error

  • message (String)

    The error message



17
18
19
20
21
# File 'lib/svg_conform/errors/base.rb', line 17

def initialize(type:, node:, message:)
  @type = type
  @node = node
  @message = message
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/svg_conform/errors/base.rb', line 10

def message
  @message
end

#nodeObject (readonly)

Returns the value of attribute node.



10
11
12
# File 'lib/svg_conform/errors/base.rb', line 10

def node
  @node
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/svg_conform/errors/base.rb', line 10

def type
  @type
end

Instance Method Details

#columnInteger?

Get the column number of the error

Returns:

  • (Integer, nil)

    The column number if available



33
34
35
# File 'lib/svg_conform/errors/base.rb', line 33

def column
  @node.respond_to?(:column) ? @node.column : nil
end

#element_nameString?

Get the element name of the error

Returns:

  • (String, nil)

    The element name if available



40
41
42
# File 'lib/svg_conform/errors/base.rb', line 40

def element_name
  @node.respond_to?(:name) ? @node.name : nil
end

#lineInteger?

Get the line number of the error

Returns:

  • (Integer, nil)

    The line number if available



26
27
28
# File 'lib/svg_conform/errors/base.rb', line 26

def line
  @node.respond_to?(:line) ? @node.line : nil
end

#to_hHash

Convert error to hash representation

Returns:

  • (Hash)

    Hash representation of the error



47
48
49
50
51
52
53
54
55
# File 'lib/svg_conform/errors/base.rb', line 47

def to_h
  {
    type: @type,
    message: @message,
    line: line,
    column: column,
    element: element_name,
  }
end