Class: Ifconf::ParseError
- Inherits:
-
Object
- Object
- Ifconf::ParseError
- Defined in:
- lib/ifconf/parse_error.rb
Overview
Records a non-fatal parsing problem with its raw fragment, reason, line number, and severity.
Constant Summary collapse
- SEVERITIES =
Set[:warning, :error].freeze
Instance Attribute Summary collapse
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#raw_fragment ⇒ Object
readonly
Returns the value of attribute raw_fragment.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #error? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(raw_fragment:, reason:, line_number:, severity:) ⇒ ParseError
constructor
A new instance of ParseError.
- #message ⇒ Object (also: #to_s)
- #to_h ⇒ Object
- #warning? ⇒ Boolean
Constructor Details
#initialize(raw_fragment:, reason:, line_number:, severity:) ⇒ ParseError
Returns a new instance of ParseError.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ifconf/parse_error.rb', line 12 def initialize(raw_fragment:, reason:, line_number:, severity:) raise Ifconf::Error, "line_number must be >= 0" if line_number.negative? raise Ifconf::Error, "severity must be :warning or :error" unless SEVERITIES.include?(severity) raise Ifconf::Error, "reason must not be empty" if reason.nil? || reason.empty? @raw_fragment = raw_fragment @reason = reason @line_number = line_number @severity = severity freeze end |
Instance Attribute Details
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
6 7 8 |
# File 'lib/ifconf/parse_error.rb', line 6 def line_number @line_number end |
#raw_fragment ⇒ Object (readonly)
Returns the value of attribute raw_fragment.
6 7 8 |
# File 'lib/ifconf/parse_error.rb', line 6 def raw_fragment @raw_fragment end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
6 7 8 |
# File 'lib/ifconf/parse_error.rb', line 6 def reason @reason end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
6 7 8 |
# File 'lib/ifconf/parse_error.rb', line 6 def severity @severity end |
Class Method Details
.build(raw:, reason:, line:, severity: :error) ⇒ Object
8 9 10 |
# File 'lib/ifconf/parse_error.rb', line 8 def self.build(raw:, reason:, line:, severity: :error) new(raw_fragment: raw, reason: reason, line_number: line, severity: severity) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
47 48 49 |
# File 'lib/ifconf/parse_error.rb', line 47 def ==(other) other.is_a?(ParseError) && to_h == other.to_h end |
#error? ⇒ Boolean
24 25 26 |
# File 'lib/ifconf/parse_error.rb', line 24 def error? @severity == :error end |
#hash ⇒ Object
53 54 55 |
# File 'lib/ifconf/parse_error.rb', line 53 def hash to_h.hash end |
#message ⇒ Object Also known as: to_s
32 33 34 |
# File 'lib/ifconf/parse_error.rb', line 32 def "line #{@line_number}: #{@reason}" end |
#to_h ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/ifconf/parse_error.rb', line 38 def to_h { raw_fragment: @raw_fragment, reason: @reason, line_number: @line_number, severity: @severity, } end |
#warning? ⇒ Boolean
28 29 30 |
# File 'lib/ifconf/parse_error.rb', line 28 def warning? @severity == :warning end |