Class: Spellr::Token
Instance Attribute Summary collapse
-
#line ⇒ Object
Returns the value of attribute line.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Class Method Summary collapse
Instance Method Summary collapse
- #byte_range ⇒ Object
- #char_range ⇒ Object
- #coordinates ⇒ Object
- #file_char_range ⇒ Object
- #file_name ⇒ Object
- #highlight(range = char_range) ⇒ Object
-
#initialize(string, line: string, location: ColumnLocation.new) ⇒ Token
constructor
A new instance of Token.
- #inspect ⇒ Object
- #lstripped_column_location(lstripped) ⇒ Object
- #replace(replacement) ⇒ Object
- #strip ⇒ Object
Methods inherited from String
Constructor Details
#initialize(string, line: string, location: ColumnLocation.new) ⇒ Token
Returns a new instance of Token.
25 26 27 28 29 |
# File 'lib/spellr/token.rb', line 25 def initialize(string, line: string, location: ColumnLocation.new) @location = location @line = line super(string) end |
Instance Attribute Details
#line ⇒ Object
Returns the value of attribute line.
17 18 19 |
# File 'lib/spellr/token.rb', line 17 def line @line end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
17 18 19 |
# File 'lib/spellr/token.rb', line 17 def location @location end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
17 18 19 |
# File 'lib/spellr/token.rb', line 17 def replacement @replacement end |
Class Method Details
Instance Method Details
#byte_range ⇒ Object
60 61 62 |
# File 'lib/spellr/token.rb', line 60 def byte_range @byte_range ||= location.byte_offset...(location.byte_offset + bytesize) end |
#char_range ⇒ Object
56 57 58 |
# File 'lib/spellr/token.rb', line 56 def char_range @char_range ||= location.char_offset...(location.char_offset + length) end |
#coordinates ⇒ Object
68 69 70 |
# File 'lib/spellr/token.rb', line 68 def coordinates location.coordinates end |
#file_char_range ⇒ Object
64 65 66 |
# File 'lib/spellr/token.rb', line 64 def file_char_range @file_char_range ||= location.absolute_char_offset...(location.absolute_char_offset + length) end |
#file_name ⇒ Object
81 82 83 |
# File 'lib/spellr/token.rb', line 81 def file_name location.file_name end |
#highlight(range = char_range) ⇒ Object
72 73 74 |
# File 'lib/spellr/token.rb', line 72 def highlight(range = char_range) "#{slice(0...(range.first))}#{Spellr::StringFormat.red slice(range)}#{slice(range.last..-1)}" end |
#inspect ⇒ Object
52 53 54 |
# File 'lib/spellr/token.rb', line 52 def inspect "#<#{self.class.name} #{to_s.inspect} @#{location}>" end |
#lstripped_column_location(lstripped) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/spellr/token.rb', line 39 def lstripped_column_location(lstripped) ColumnLocation.new( byte_offset: bytesize - lstripped.bytesize, char_offset: length - lstripped.length, line_location: location.line_location ) end |
#replace(replacement) ⇒ Object
76 77 78 79 |
# File 'lib/spellr/token.rb', line 76 def replace(replacement) @replacement = replacement location.file.insert(replacement, file_char_range) end |