Exception: Nanaimo::Reader::ParseError

Inherits:
Error
  • Object
show all
Defined in:
lib/nanaimo/reader.rb

Overview

Raised when parsing fails.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#location[Integer, Integer]

Returns The (line, column) offset into the plist where the error occurred.

Returns:

  • ([Integer, Integer])

    The (line, column) offset into the plist where the error occurred



31
32
33
# File 'lib/nanaimo/reader.rb', line 31

def location
  @location
end

#plist_stringString

Returns The contents of the plist.

Returns:

  • (String)

    The contents of the plist.



35
36
37
# File 'lib/nanaimo/reader.rb', line 35

def plist_string
  @plist_string
end

Instance Method Details

#context(n = 2) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/nanaimo/reader.rb', line 41

def context(n = 2)
  line_number, column = location
  line_number -= 1
  lines = plist_string.split(NEWLINE)

  s = line_number.succ.to_s.size
  indent     = "#{' ' * s}#  "
  indicator  = "#{line_number.succ}>  "

  m =  ::String.new("\n")

  m << "#{indent}-------------------------------------------\n"
  m << lines[[line_number - n, 0].max...line_number].map do |l|
    "#{indent}#{l}\n"
  end.join

  line = lines[line_number].to_s
  m << "#{indicator}#{line}\n"

  m << ' ' * indent.size
  m << line[0, column.pred].gsub(/[^\t]/, ' ')
  m << "^\n"

  m << Array(lines[line_number.succ..[lines.count.pred, line_number + n].min]).map do |l|
    l.strip.empty? ? '' : "#{indent}#{l}\n"
  end.join
  m << "#{indent}-------------------------------------------\n"
end

#to_sObject



37
38
39
# File 'lib/nanaimo/reader.rb', line 37

def to_s
  "[!] #{super}#{context}"
end