Class: RNV::Error
- Inherits:
-
Object
- Object
- RNV::Error
- Defined in:
- lib/rnv/error.rb,
ext/rnv/ruby_rnv.c
Instance Attribute Summary collapse
-
#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.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#xpath ⇒ Object
readonly
Returns the value of attribute xpath.
Instance Method Summary collapse
- #allowed ⇒ Object
- #compact_expected ⇒ String
- #compact_message ⇒ String
-
#contextualize(data, max_len = 60) ⇒ String
Context.
- #expected ⇒ String
- #inspect ⇒ String
- #message ⇒ String
- #required ⇒ Object
- #to_s ⇒ String
Instance Attribute Details
#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 @original_message end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/rnv/error.rb', line 4 def value @value end |
#xpath ⇒ Object (readonly)
Returns the value of attribute xpath.
5 6 7 |
# File 'lib/rnv/error.rb', line 5 def xpath @xpath end |
Instance Method Details
#allowed ⇒ Object
74 75 76 |
# File 'lib/rnv/error.rb', line 74 def allowed @allowed.select{|a| @attr ? a.first == :rn_p_attribute : true} end |
#compact_expected ⇒ String
36 37 38 39 |
# File 'lib/rnv/error.rb', line 36 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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rnv/error.rb', line 18 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 @original_message end end |
#contextualize(data, max_len = 60) ⇒ String
Returns context.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rnv/error.rb', line 43 def contextualize(data, max_len = 60) out = "" if data and @line err_data = data.split("\n")[@line - 1] if err_data && err_data.length > @col - 1 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
13 14 15 |
# File 'lib/rnv/error.rb', line 13 def expected @original_expected end |
#inspect ⇒ String
66 67 68 |
# File 'lib/rnv/error.rb', line 66 def inspect "#<RNV::Error code: :#{@code}, message: '#{self.}', expected: '#{self.expected}, line: #{@line}, column: #{@col}>" end |
#message ⇒ String
8 9 10 |
# File 'lib/rnv/error.rb', line 8 def @original_message end |
#required ⇒ Object
70 71 72 |
# File 'lib/rnv/error.rb', line 70 def required @required.select{|a| @attr ? a.first == :rn_p_attribute : true} end |
#to_s ⇒ String
61 62 63 |
# File 'lib/rnv/error.rb', line 61 def to_s "#{@line}:#{@col}:error: #{self.}\n#{self.expected}" end |