Class: Arugula::MetacharacterPart

Inherits:
Part
  • Object
show all
Defined in:
lib/arugula/parts.rb

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

Methods inherited from Part

all, inherited, type

Constructor Details

#initialize(metachar) ⇒ MetacharacterPart

Returns a new instance of MetacharacterPart.



113
114
115
# File 'lib/arugula/parts.rb', line 113

def initialize(metachar)
  @metachar = metachar.to_sym
end

Instance Method Details

#match(str, index) ⇒ Object



117
118
119
# File 'lib/arugula/parts.rb', line 117

def match(str, index)
  [MATCHERS[@metachar][str, index], index + OFFSETS[@metachar]]
end

#to_sObject



121
122
123
# File 'lib/arugula/parts.rb', line 121

def to_s
  "\\#{@metachar}"
end