Class: Regexp::Expression::Group::Base

Inherits:
Subexpression show all
Defined in:
lib/regexp_parser/expression/classes/group.rb

Direct Known Subclasses

Assertion::Base, Atomic, Capture, Comment, Options, Passive

Instance Attribute Summary

Attributes inherited from Subexpression

#expressions

Attributes inherited from Base

#level, #options, #quantifier, #text, #token, #ts, #type

Instance Method Summary collapse

Methods inherited from Subexpression

#<<, #[], #clone, #each, #each_with_index, #first, #initialize, #insert, #last, #length

Methods inherited from Base

#case_insensitive?, #clone, #coded_offset, #free_spacing?, #full_length, #greedy?, #initialize, #multiline?, #offset, #possessive?, #quantified?, #quantify, #quantity, #reluctant?, #starts_at, #terminal?, #to_re

Constructor Details

This class inherits a constructor from Regexp::Expression::Subexpression

Instance Method Details

#capturing?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/regexp_parser/expression/classes/group.rb', line 5

def capturing?
  [:capture, :named].include? @token
end

#comment?Boolean

Returns:

  • (Boolean)


9
# File 'lib/regexp_parser/expression/classes/group.rb', line 9

def comment?; @type == :comment end

#to_s(format = :full) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/regexp_parser/expression/classes/group.rb', line 11

def to_s(format = :full)
  s = ''

  case format
  when :base
    s << @text.dup
    s << @expressions.join
    s << ')'
  else
    s << @text.dup
    s << @expressions.join
    s << ')'
    s << @quantifier.to_s if quantified?
  end

  s
end