Class: Regexp::Token

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

Instance Method Summary collapse

Constructor Details

#initializeToken

Returns a new instance of Token.



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

def initialize(*)
  super

  @previous = @next = nil
end

Instance Method Details

#lengthObject



25
26
27
# File 'lib/regexp_parser/token.rb', line 25

def length
  self.te - self.ts
end

#next(exp = nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/regexp_parser/token.rb', line 29

def next(exp = nil)
  if exp
    @next = exp
  else
    @next
  end
end

#offsetObject



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

def offset
  [self.ts, self.te]
end

#previous(exp = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/regexp_parser/token.rb', line 37

def previous(exp = nil)
  if exp
    @previous = exp
  else
    @previous
  end
end

#to_hObject



46
47
48
49
50
51
52
53
54
# File 'lib/regexp_parser/token.rb', line 46

def to_h
  hash = {}

  members.each do |member|
    hash[member.to_sym] = self.send(member.to_sym)
  end

  hash
end