Class: Arugula::MetacharacterPart
Constant Summary collapse
- MATCHERS =
{ A: ->(_str, index) { index == 0 }, d: ->(str, index) { ('0'..'9').member?(str[index]) }, s: ->(str, index) { [' ', "\t"].include?(str[index]) }, S: ->(str, index) { ![' ', "\t"].include?(str[index]) }, }.freeze
- OFFSETS =
begin offsets = { A: 0, } offsets.default = 1 offsets.freeze end
Instance Method Summary collapse
-
#initialize(metachar) ⇒ MetacharacterPart
constructor
A new instance of MetacharacterPart.
- #match(str, index, _match_data) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Part
Constructor Details
#initialize(metachar) ⇒ MetacharacterPart
Returns a new instance of MetacharacterPart.
121 122 123 |
# File 'lib/arugula/parts.rb', line 121 def initialize() @metachar = .to_sym end |
Instance Method Details
#match(str, index, _match_data) ⇒ Object
125 126 127 128 |
# File 'lib/arugula/parts.rb', line 125 def match(str, index, _match_data) matches = MATCHERS[@metachar][str, index] [matches, index + (matches ? OFFSETS[@metachar] : 0)] end |
#to_s ⇒ Object
130 131 132 |
# File 'lib/arugula/parts.rb', line 130 def to_s "\\#{@metachar}" end |