Class: RLSM::RE::Position

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/rlsm/regexp_parser.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char, index = nil) ⇒ Position

Returns a new instance of Position.



76
77
78
79
# File 'lib/rlsm/regexp_parser.rb', line 76

def initialize(char, index = nil)
  @letter = char
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



81
82
83
# File 'lib/rlsm/regexp_parser.rb', line 81

def index
  @index
end

#letterObject (readonly)

Returns the value of attribute letter.



81
82
83
# File 'lib/rlsm/regexp_parser.rb', line 81

def letter
  @letter
end

Instance Method Details

#<=>(other) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rlsm/regexp_parser.rb', line 83

def <=>(other)
  case other
  when String
    @letter <=> other
  when Numeric
    @index <=> other
  when Position
    @letter == other.letter ? @index <=> other.index : @letter <=> other.letter
  else
    nil
  end
end

#inspectObject



107
108
109
# File 'lib/rlsm/regexp_parser.rb', line 107

def inspect
  "P(#@letter,#@index)"
end

#to_sObject



103
104
105
# File 'lib/rlsm/regexp_parser.rb', line 103

def to_s
  @letter
end

#weightObject



96
97
98
99
100
101
# File 'lib/rlsm/regexp_parser.rb', line 96

def weight
  return 1 if Parser.open_bracket?(@letter)
  return -1 if Parser.close_bracket?(@letter)

  0
end