Class: RbYAML::Mark
- Defined in:
- lib/rbyaml/error.rb,
lib/rbyaml/error.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#column ⇒ Object
Returns the value of attribute column.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pointer ⇒ Object
Returns the value of attribute pointer.
Instance Method Summary collapse
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer
3 4 5 |
# File 'lib/rbyaml/error.rb', line 3 def buffer @buffer end |
#column ⇒ Object
Returns the value of attribute column
3 4 5 |
# File 'lib/rbyaml/error.rb', line 3 def column @column end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/rbyaml/error.rb', line 3 def name @name end |
#pointer ⇒ Object
Returns the value of attribute 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 |
#hash ⇒ Object
39 40 41 |
# File 'lib/rbyaml/error.rb', line 39 def hash object_id end |
#to_s ⇒ Object
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 |