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]) }, z: ->(str, index) { index == str.size }, Z: ->(str, index) { str[index..-1] == "\n" || index == str.size }, }.freeze
- OFFSETS =
begin offsets = { A: ->(_str, _index) { 0 }, Z: ->(_str, _index) { 0 }, z: ->(_str, _index) { 0 }, } offsets.default = ->(_str, _index) { 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.
132 133 134 |
# File 'lib/arugula/parts.rb', line 132 def initialize() @metachar = .to_sym end |
Instance Method Details
#match(str, index, _match_data) ⇒ Object
136 137 138 139 |
# File 'lib/arugula/parts.rb', line 136 def match(str, index, _match_data) matches = MATCHERS[@metachar][str, index] [matches, index + (matches ? OFFSETS[@metachar][str, index] : 0)] end |
#to_s ⇒ Object
141 142 143 |
# File 'lib/arugula/parts.rb', line 141 def to_s "\\#{@metachar}" end |