Class: HashSyntax::Token

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Token

Unpacks the token from Ripper and breaks it into its separate components.

Parameters:

  • token (Array<Array<Integer, Integer>, Symbol, String>)

    the token from Ripper that we’re wrapping



7
8
9
# File 'lib/hash_syntax/token.rb', line 7

def initialize(token)
  (self.line, self.col), self.type, self.body = token
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



2
3
4
# File 'lib/hash_syntax/token.rb', line 2

def body
  @body
end

#colObject

Returns the value of attribute col

Returns:

  • (Object)

    the current value of col



2
3
4
# File 'lib/hash_syntax/token.rb', line 2

def col
  @col
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



2
3
4
# File 'lib/hash_syntax/token.rb', line 2

def line
  @line
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



2
3
4
# File 'lib/hash_syntax/token.rb', line 2

def type
  @type
end

Instance Method Details

#reg_descObject



15
16
17
18
19
20
21
# File 'lib/hash_syntax/token.rb', line 15

def reg_desc
  if type == :on_op && body == '=>'
    'hashrocket'
  else
    type.to_s.sub(/^on_/, '')
  end
end

#widthObject



11
12
13
# File 'lib/hash_syntax/token.rb', line 11

def width
  body.size
end