Class: Spellr::LineLocation
- Inherits:
-
Object
- Object
- Spellr::LineLocation
- Defined in:
- lib/spellr/line_location.rb
Instance Attribute Summary collapse
-
#byte_offset ⇒ Object
readonly
Returns the value of attribute byte_offset.
-
#char_offset ⇒ Object
readonly
Returns the value of attribute char_offset.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
Instance Method Summary collapse
- #advance(line) ⇒ Object
- #file ⇒ Object
- #file_relative_path ⇒ Object
-
#initialize(file = '[String]', line_number = 1, char_offset: 0, byte_offset: 0) ⇒ LineLocation
constructor
A new instance of LineLocation.
- #to_s ⇒ Object
Constructor Details
#initialize(file = '[String]', line_number = 1, char_offset: 0, byte_offset: 0) ⇒ LineLocation
Returns a new instance of LineLocation.
9 10 11 12 13 14 |
# File 'lib/spellr/line_location.rb', line 9 def initialize(file = '[String]', line_number = 1, char_offset: 0, byte_offset: 0) @filename = file @line_number = line_number @char_offset = char_offset @byte_offset = byte_offset end |
Instance Attribute Details
#byte_offset ⇒ Object (readonly)
Returns the value of attribute byte_offset.
7 8 9 |
# File 'lib/spellr/line_location.rb', line 7 def byte_offset @byte_offset end |
#char_offset ⇒ Object (readonly)
Returns the value of attribute char_offset.
6 7 8 |
# File 'lib/spellr/line_location.rb', line 6 def char_offset @char_offset end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
5 6 7 |
# File 'lib/spellr/line_location.rb', line 5 def line_number @line_number end |
Instance Method Details
#advance(line) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/spellr/line_location.rb', line 28 def advance(line) LineLocation.new(@filename, line_number + 1, char_offset: char_offset + line.length, byte_offset: byte_offset + line.bytesize) end |
#file ⇒ Object
24 25 26 |
# File 'lib/spellr/line_location.rb', line 24 def file @file ||= Spellr::File.wrap(@filename) end |
#file_relative_path ⇒ Object
20 21 22 |
# File 'lib/spellr/line_location.rb', line 20 def file_relative_path file.relative_path end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/spellr/line_location.rb', line 16 def to_s "#{file_relative_path}:#{line_number}" end |