Class: RNV::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/rnv/error.rb,
ext/rnv/ruby_rnv.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrObject (readonly)

Returns the value of attribute attr.



4
5
6
# File 'lib/rnv/error.rb', line 4

def attr
  @attr
end

#codeSymbol (readonly)

error symbol code

Returns:

  • (Symbol)

#colInteger (readonly)

error column

Returns:

  • (Integer)

#elementObject (readonly)

Returns the value of attribute element.



4
5
6
# File 'lib/rnv/error.rb', line 4

def element
  @element
end

#lineInteger (readonly)

error line

Returns:

  • (Integer)

#ns_uriObject (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_expectedObject (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_messageObject (readonly)

Returns the value of attribute original_message.



3
4
5
# File 'lib/rnv/error.rb', line 3

def original_message
  @original_message
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/rnv/error.rb', line 4

def value
  @value
end

#xpathObject (readonly)

Returns the value of attribute xpath.



5
6
7
# File 'lib/rnv/error.rb', line 5

def xpath
  @xpath
end

Instance Method Details

#allowedObject



74
75
76
# File 'lib/rnv/error.rb', line 74

def allowed
  @allowed.select{|a| @attr ? a.first == :rn_p_attribute : true}
end

#compact_expectedString

Returns:

  • (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_messageString

Returns:

  • (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 compact_message
  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.

Parameters:

  • data (String)

    original content

Returns:

  • (String)

    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

#expectedString

Returns:

  • (String)


13
14
15
# File 'lib/rnv/error.rb', line 13

def expected
  @original_expected
end

#inspectString

Returns:

  • (String)


66
67
68
# File 'lib/rnv/error.rb', line 66

def inspect
  "#<RNV::Error code: :#{@code}, message: '#{self.message}', expected: '#{self.expected}, line: #{@line}, column: #{@col}>"
end

#messageString

Returns:

  • (String)


8
9
10
# File 'lib/rnv/error.rb', line 8

def message
  @original_message
end

#requiredObject



70
71
72
# File 'lib/rnv/error.rb', line 70

def required
  @required.select{|a| @attr ? a.first == :rn_p_attribute : true}
end

#to_sString

Returns:

  • (String)


61
62
63
# File 'lib/rnv/error.rb', line 61

def to_s
  "#{@line}:#{@col}:error: #{self.message}\n#{self.expected}"
end