Class: Regex::Anchor

Inherits:
AtomicExpression show all
Defined in:
lib/regex/anchor.rb

Overview

An anchor is a zero-width assertion based on the current position.

Constant Summary collapse

AnchorToSymbol =

A Hash for converting a lexeme to a symbolic value

{
  # Lexeme => Symbol value
  '^' => :soLine, # Start of line
  '$' => :eoLine, # End of line
  '\A' => :soSubject,
  '\b' => :wordBoundary,
  '\B' => :nonAtWordBoundary,
  '\G' => :firstMatch,
  '\z' => :eoSubject,
  '\Z' => :eoSubjectOrBeforeNLAtEnd
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Expression

#begin_anchor, #end_anchor

Instance Method Summary collapse

Methods inherited from AtomicExpression

#atomic?, #done!, #lazy!

Methods inherited from Expression

#atomic?, #options

Constructor Details

#initialize(aKind) ⇒ Anchor

Constructor

Parameters:

  • aKind (String)

    Lexeme representation of the anchor



26
27
28
# File 'lib/regex/anchor.rb', line 26

def initialize(aKind)
  @kind = valid_kind(aKind)
end

Instance Attribute Details

#kindObject (readonly)

A symbolic value that identifies the type of assertion to perform



22
23
24
# File 'lib/regex/anchor.rb', line 22

def kind
  @kind
end

Instance Method Details

#to_strObject

Conversion method re-definition. Purpose: Return the String representation of the expression.



32
33
34
# File 'lib/regex/anchor.rb', line 32

def to_str
  AnchorToSymbol.rassoc(kind).first
end