Class: Uniword::Warnings::Warning
- Inherits:
-
Object
- Object
- Uniword::Warnings::Warning
- Defined in:
- lib/uniword/warnings/warning.rb
Overview
Represents a single warning about an unsupported element or feature.
Responsibility: Store information about one warning. Single Responsibility: Only represents warning data.
A warning includes:
-
Type (unsupported_element, unsupported_attribute, etc.)
-
Severity (error, warning, info)
-
Element/attribute name
-
Context where it was encountered
-
Location in document
-
Suggestion for user
Instance Attribute Summary collapse
-
#attribute ⇒ String?
readonly
Attribute name (for attribute warnings).
-
#context ⇒ String?
readonly
Context where warning occurred.
-
#element ⇒ String
readonly
Element name.
-
#location ⇒ String?
readonly
Location in document.
-
#message ⇒ String
readonly
Warning message.
-
#severity ⇒ Symbol
readonly
Severity level (:error, :warning, :info).
-
#suggestion ⇒ String?
readonly
Suggestion for user.
-
#type ⇒ Symbol
readonly
Type of warning.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Check if this is an error-level warning.
-
#info? ⇒ Boolean
Check if this is an info-level warning.
-
#initialize(attributes) ⇒ Warning
constructor
Initialize a new warning.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_s ⇒ String
Convert to string for display.
-
#warning? ⇒ Boolean
Check if this is a warning-level warning.
Constructor Details
#initialize(attributes) ⇒ Warning
Initialize a new warning.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/uniword/warnings/warning.rb', line 71 def initialize(attributes) @type = attributes[:type] @severity = attributes[:severity] @element = attributes[:element] @attribute = attributes[:attribute] @message = attributes[:message] @context = attributes[:context] @location = attributes[:location] @suggestion = attributes[:suggestion] end |
Instance Attribute Details
#attribute ⇒ String? (readonly)
Returns Attribute name (for attribute warnings).
38 39 40 |
# File 'lib/uniword/warnings/warning.rb', line 38 def attribute @attribute end |
#context ⇒ String? (readonly)
Returns Context where warning occurred.
44 45 46 |
# File 'lib/uniword/warnings/warning.rb', line 44 def context @context end |
#element ⇒ String (readonly)
Returns Element name.
35 36 37 |
# File 'lib/uniword/warnings/warning.rb', line 35 def element @element end |
#location ⇒ String? (readonly)
Returns Location in document.
47 48 49 |
# File 'lib/uniword/warnings/warning.rb', line 47 def location @location end |
#message ⇒ String (readonly)
Returns Warning message.
41 42 43 |
# File 'lib/uniword/warnings/warning.rb', line 41 def @message end |
#severity ⇒ Symbol (readonly)
Returns Severity level (:error, :warning, :info).
32 33 34 |
# File 'lib/uniword/warnings/warning.rb', line 32 def severity @severity end |
#suggestion ⇒ String? (readonly)
Returns Suggestion for user.
50 51 52 |
# File 'lib/uniword/warnings/warning.rb', line 50 def suggestion @suggestion end |
#type ⇒ Symbol (readonly)
Returns Type of warning.
29 30 31 |
# File 'lib/uniword/warnings/warning.rb', line 29 def type @type end |
Instance Method Details
#error? ⇒ Boolean
Check if this is an error-level warning.
85 86 87 |
# File 'lib/uniword/warnings/warning.rb', line 85 def error? @severity == :error end |
#info? ⇒ Boolean
Check if this is an info-level warning.
99 100 101 |
# File 'lib/uniword/warnings/warning.rb', line 99 def info? @severity == :info end |
#to_h ⇒ Hash
Convert to hash representation.
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/uniword/warnings/warning.rb', line 106 def to_h { type: @type, severity: @severity, element: @element, attribute: @attribute, message: @message, context: @context, location: @location, suggestion: @suggestion, }.compact end |
#to_s ⇒ String
Convert to string for display.
122 123 124 125 126 127 |
# File 'lib/uniword/warnings/warning.rb', line 122 def to_s severity_str = @severity.to_s.upcase element_str = @attribute ? "#{@element}/@#{@attribute}" : @element msg_str = @message "[#{severity_str}] #{element_str}: #{msg_str}" end |
#warning? ⇒ Boolean
Check if this is a warning-level warning.
92 93 94 |
# File 'lib/uniword/warnings/warning.rb', line 92 def warning? @severity == :warning end |