Class: Regex::Lookaround
- Inherits:
-
MonadicExpression
- Object
- Expression
- CompoundExpression
- MonadicExpression
- Regex::Lookaround
- Defined in:
- lib/regex/lookaround.rb
Overview
Lookaround is a zero-width assertion just like the start and end of line anchors. The difference is that lookarounds will actually match characters, but only return the result of the match: match or no match. That is why they are called "assertions". They do not consume characters from the subject, but only assert whether a match is possible or not.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
The "direction" of the lookaround.
-
#kind ⇒ Object
readonly
The kind indicates whether the assertion is positive (succeeds when there is a match) or negative (assertion succeeds when there is NO match).
Attributes inherited from MonadicExpression
Attributes inherited from Expression
Instance Method Summary collapse
-
#initialize(assertedExpression, theDir, theKind) ⇒ Lookaround
constructor
Constructor.
-
#to_str ⇒ Object
Conversion method re-definition.
Methods inherited from MonadicExpression
Methods inherited from CompoundExpression
Methods inherited from Expression
Constructor Details
#initialize(assertedExpression, theDir, theKind) ⇒ Lookaround
Constructor. [assertedExpression] A sub-expression to match. [theDir] One of the following values: [ :ahead, :behind ] [theKind] One of the following values: [ :positive, :negative ]
34 35 36 37 38 |
# File 'lib/regex/lookaround.rb', line 34 def initialize(assertedExpression, theDir, theKind) super(assertedExpression) @dir = theDir @kind = theKind end |
Instance Attribute Details
#dir ⇒ Object (readonly)
The "direction" of the lookaround. Can be ahead or behind. It specifies the relative position of the expression to match compared to the current 'position' in the subject text.
23 24 25 |
# File 'lib/regex/lookaround.rb', line 23 def dir @dir end |
#kind ⇒ Object (readonly)
The kind indicates whether the assertion is positive (succeeds when there is a match) or negative (assertion succeeds when there is NO match).
28 29 30 |
# File 'lib/regex/lookaround.rb', line 28 def kind @kind end |
Instance Method Details
#to_str ⇒ Object
Conversion method re-definition. Purpose: Return the String representation of the captured expression.
42 43 44 45 46 47 |
# File 'lib/regex/lookaround.rb', line 42 def to_str dir_syntax = (dir == :ahead) ? '' : '<' kind_syntax = (kind == :positive) ? '=' : '!' result = "(?#{dir_syntax}#{kind_syntax}#{child.to_str})" return result end |