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.
Instance Method Summary collapse
-
#byte_range ⇒ Object
leftovers:allow i don’t want to delete this.
- #case_method ⇒ Object
-
#char_range ⇒ Object
:nocov:.
- #coordinates ⇒ Object
-
#file_byte_range ⇒ Object
leftovers:allow i don’t want to delete this.
- #file_char_range ⇒ Object
- #highlight(range = char_range) ⇒ Object
-
#initialize(string, line: string, location: ColumnLocation.new) ⇒ Token
constructor
A new instance of Token.
-
#inspect ⇒ Object
:nocov:.
- #replace(replacement) ⇒ Object
Methods inherited from String
Constructor Details
#initialize(string, line: string, location: ColumnLocation.new) ⇒ Token
Returns a new instance of Token.
20 21 22 23 24 |
# File 'lib/spellr/token.rb', line 20 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.
18 19 20 |
# File 'lib/spellr/token.rb', line 18 def line @line end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
18 19 20 |
# File 'lib/spellr/token.rb', line 18 def location @location end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
18 19 20 |
# File 'lib/spellr/token.rb', line 18 def replacement @replacement end |
Instance Method Details
#byte_range ⇒ Object
leftovers:allow i don’t want to delete this
42 43 44 45 |
# File 'lib/spellr/token.rb', line 42 def byte_range # leftovers:allow i don't want to delete this @byte_range ||= location.byte_offset...(location.byte_offset + bytesize) end |
#case_method ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/spellr/token.rb', line 70 def case_method @case_method ||= case self when /\A[[:lower:]]+\z/ then :downcase when /\A[[:upper:]]+\z/ then :upcase when /\A[[:upper:]][[:lower:]]*\z/ then :capitalize else :itself end end |
#char_range ⇒ Object
:nocov:
37 38 39 40 |
# File 'lib/spellr/token.rb', line 37 def char_range @char_range ||= location.char_offset...(location.char_offset + length) end |
#coordinates ⇒ Object
57 58 59 |
# File 'lib/spellr/token.rb', line 57 def coordinates location.coordinates end |
#file_byte_range ⇒ Object
leftovers:allow i don’t want to delete this
52 53 54 55 |
# File 'lib/spellr/token.rb', line 52 def file_byte_range # leftovers:allow i don't want to delete this @file_byte_range ||= location.absolute_byte_offset...(location.absolute_byte_offset + bytesize) end |
#file_char_range ⇒ Object
47 48 49 50 |
# File 'lib/spellr/token.rb', line 47 def file_char_range @file_char_range ||= location.absolute_char_offset...(location.absolute_char_offset + length) end |
#highlight(range = char_range) ⇒ Object
61 62 63 |
# File 'lib/spellr/token.rb', line 61 def highlight(range = char_range) "#{slice(0...(range.first))}#{Spellr::StringFormat.red slice(range)}#{slice(range.last..-1)}" end |
#inspect ⇒ Object
:nocov:
32 33 34 |
# File 'lib/spellr/token.rb', line 32 def inspect "#<#{self.class.name} #{to_s.inspect} @#{location}>" end |
#replace(replacement) ⇒ Object
65 66 67 68 |
# File 'lib/spellr/token.rb', line 65 def replace(replacement) @replacement = replacement location.file.insert(replacement, file_char_range) end |