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

#allowedObject (readonly)

Returns the value of attribute allowed.



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

def allowed
  @allowed
end

#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

#requiredObject (readonly)

Returns the value of attribute required.



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

def required
  @required
end

#valueObject (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_expectedString

Returns:

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

Returns:

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



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

#expectedString

Returns:

  • (String)


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

def expected
  @original_expected
end

#inspectString

Returns:

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

#messageString

Returns:

  • (String)


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

def message
  @original_message
end

#to_sString

Returns:

  • (String)


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

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