Class: RNV::Error
- Inherits:
-
Object
- Object
- RNV::Error
- Defined in:
- lib/rnv/error.rb,
ext/rnv/ruby_rnv.c
Instance Attribute Summary collapse
-
#allowed ⇒ Object
readonly
Returns the value of attribute allowed.
-
#attr ⇒ Object
readonly
Returns the value of attribute attr.
-
#code ⇒ Symbol
readonly
error symbol code.
-
#col ⇒ Integer
readonly
error column.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#line ⇒ Integer
readonly
error line.
-
#ns_uri ⇒ Object
readonly
Returns the value of attribute ns_uri.
-
#original_expected ⇒ Object
readonly
Returns the value of attribute original_expected.
-
#original_message ⇒ Object
readonly
Returns the value of attribute original_message.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #compact_expected ⇒ String
- #compact_message ⇒ String
-
#contextualize(data, max_len = 60) ⇒ String
Context.
- #expected ⇒ String
- #inspect ⇒ String
- #message ⇒ String
- #to_s ⇒ String
Instance Attribute Details
#allowed ⇒ Object (readonly)
Returns the value of attribute allowed.
4 5 6 |
# File 'lib/rnv/error.rb', line 4 def allowed @allowed end |
#attr ⇒ Object (readonly)
Returns the value of attribute attr.
4 5 6 |
# File 'lib/rnv/error.rb', line 4 def attr @attr end |
#code ⇒ Symbol (readonly)
error symbol code
#col ⇒ Integer (readonly)
error column
#element ⇒ Object (readonly)
Returns the value of attribute element.
4 5 6 |
# File 'lib/rnv/error.rb', line 4 def element @element end |
#line ⇒ Integer (readonly)
error line
#ns_uri ⇒ Object (readonly)
Returns the value of attribute ns_uri.
4 5 6 |
# File 'lib/rnv/error.rb', line 4 def ns_uri @ns_uri end |
#original_expected ⇒ Object (readonly)
Returns the value of attribute original_expected.
3 4 5 |
# File 'lib/rnv/error.rb', line 3 def original_expected @original_expected end |
#original_message ⇒ Object (readonly)
Returns the value of attribute original_message.
3 4 5 |
# File 'lib/rnv/error.rb', line 3 def end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
4 5 6 |
# File 'lib/rnv/error.rb', line 4 def required @required end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/rnv/error.rb', line 4 def value @value end |
Instance Method Details
#compact_expected ⇒ String
35 36 37 38 |
# File 'lib/rnv/error.rb', line 35 def compact_expected [(compact_required_set.length > 0 ? compact_expected_phrase(compact_required_set) +" required" : nil), (compact_allowed_set.length > 0 ? compact_expected_phrase(compact_allowed_set) + " allowed" : nil)].join("; ") end |
#compact_message ⇒ String
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rnv/error.rb', line 17 def case @code when :rnv_er_elem "element <#{@element}> is not allowed" when :rnv_er_ufin "element <#{@element}> is incomplete" when :rnv_er_akey "attribute #{@attr} is not allowed" when :rnv_er_aval "attribute #{@attr} has invalid value '#{@value}'" when :rnv_er_amis "element <#{@element}> attribute missing" else end end |
#contextualize(data, max_len = 60) ⇒ String
Returns context.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rnv/error.rb', line 42 def contextualize(data, max_len = 60) out = "" if data and @line err_data = data.split("\n")[@line - 1] if err_data err_data.insert(@col - 1, "🢑") start = 0 if @col > max_len start = @col - max_len end out += (start > 0 ? "…" : "") + err_data[start..(@col + max_len)].strip + (@col + max_len < err_data.length ? "…" : "") end end out end |
#expected ⇒ String
12 13 14 |
# File 'lib/rnv/error.rb', line 12 def expected @original_expected end |
#inspect ⇒ String
65 66 67 |
# File 'lib/rnv/error.rb', line 65 def inspect "#<RNV::Error code: :#{@code}, message: '#{self.message}', expected: '#{self.expected}, line: #{@line}, column: #{@col}>" end |
#message ⇒ String
7 8 9 |
# File 'lib/rnv/error.rb', line 7 def end |
#to_s ⇒ String
60 61 62 |
# File 'lib/rnv/error.rb', line 60 def to_s "#{@line}:#{@col}:error: #{self.message}\n#{self.expected}" end |