Class: RbYAML::Mark

Inherits:
Struct show all
Defined in:
lib/rbyaml/error.rb,
lib/rbyaml/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer

Returns:

  • (Object)

    the current value of buffer



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

def buffer
  @buffer
end

#columnObject

Returns the value of attribute column

Returns:

  • (Object)

    the current value of column



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

def column
  @column
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



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

def name
  @name
end

#pointerObject

Returns the value of attribute pointer

Returns:

  • (Object)

    the current value of pointer



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

def pointer
  @pointer
end

Instance Method Details

#get_snippet(indent = 4, max_length = 75) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rbyaml/error.rb', line 5

def get_snippet(indent=4, max_length=75)
  return nil if buffer.nil?
  head = ""
  start = pointer
  while start > 0 && !"\0\r\n\x85".include?(buffer[start-1])
    start -= 1
    if pointer-start > max_length/2-1
      head = " ... "
      start += 5
      break
    end
  end
  tail = ""
  tend = pointer
  while tend < buffer.length && !"\0\r\n\x85".include?(buffer[tend])
    tend += 1
    if tend-pointer > max_length/2-1
      tail = " ... "
      tend -= 5
      break
    end
  end
  snippet = buffer[start..tend]
  ' ' * indent + "#{head}#{snippet}#{tail}\n" + ' '*(indent+pointer-start+head.length) + ' '
end

#hashObject



39
40
41
# File 'lib/rbyaml/error.rb', line 39

def hash
  object_id
end

#to_sObject



31
32
33
34
35
36
37
# File 'lib/rbyaml/error.rb', line 31

def to_s
  snippet = get_snippet()
  where = "  in \"#{name}\", line ?, column #{column+1}"
  if snippet
    where << ":\n" << snippet
  end
end