Class: RuboCop::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/token.rb

Overview

A basic wrapper around Parser’s tokens.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pos, type, text) ⇒ Token

Returns a new instance of Token.



14
15
16
17
18
19
# File 'lib/rubocop/token.rb', line 14

def initialize(pos, type, text)
  @pos = pos
  @type = type
  # Parser token "text" may be an Integer
  @text = text.to_s
end

Instance Attribute Details

#posObject (readonly)

Returns the value of attribute pos.



6
7
8
# File 'lib/rubocop/token.rb', line 6

def pos
  @pos
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/rubocop/token.rb', line 6

def text
  @text
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/rubocop/token.rb', line 6

def type
  @type
end

Class Method Details

.from_parser_token(parser_token) ⇒ Object



8
9
10
11
12
# File 'lib/rubocop/token.rb', line 8

def self.from_parser_token(parser_token)
  type, details = parser_token
  text, range = details
  new(range, type, text)
end

Instance Method Details

#to_sObject



21
22
23
# File 'lib/rubocop/token.rb', line 21

def to_s
  "[[#{@pos.line}, #{@pos.column}], #{@type}, #{@text.inspect}]"
end