Class: Regexp::Expression::Subexpression
- Inherits:
-
Base
- Object
- Base
- Regexp::Expression::Subexpression
show all
- Defined in:
- lib/regexp_parser/expression/subexpression.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#level, #options, #quantifier, #text, #token, #ts, #type
Instance Method Summary
collapse
Methods inherited from Base
#case_insensitive?, #coded_offset, #free_spacing?, #full_length, #greedy?, #multiline?, #offset, #possessive?, #quantified?, #quantify, #quantity, #reluctant?, #starts_at, #terminal?, #to_re
Constructor Details
Returns a new instance of Subexpression.
6
7
8
9
10
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 6
def initialize(token)
super(token)
@expressions = []
end
|
Instance Attribute Details
#expressions ⇒ Object
Returns the value of attribute expressions.
4
5
6
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 4
def expressions
@expressions
end
|
Instance Method Details
#<<(exp) ⇒ Object
19
20
21
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 19
def <<(exp)
@expressions << exp
end
|
#[](index) ⇒ Object
43
44
45
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 43
def [](index)
@expressions[index]
end
|
#clone ⇒ Object
Override base method to clone the expressions as well.
13
14
15
16
17
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 13
def clone
copy = super
copy.expressions = @expressions.map {|e| e.clone }
copy
end
|
#each(&block) ⇒ Object
27
28
29
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 27
def each(&block)
@expressions.each {|e| yield e}
end
|
#each_with_index(&block) ⇒ Object
31
32
33
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 31
def each_with_index(&block)
@expressions.each_with_index {|e, i| yield e, i}
end
|
#first ⇒ Object
35
36
37
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 35
def first
@expressions.first
end
|
#insert(exp) ⇒ Object
23
24
25
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 23
def insert(exp)
@expressions.insert 0, exp
end
|
#last ⇒ Object
39
40
41
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 39
def last
@expressions.last
end
|
#length ⇒ Object
47
48
49
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 47
def length
@expressions.length
end
|
#to_s(format = :full) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/regexp_parser/expression/subexpression.rb', line 51
def to_s(format = :full)
s = ''
case format
when :base
s << @text.dup
s << @expressions.map{|e| e.to_s}.join unless @expressions.empty?
else
s << @text.dup
s << @expressions.map{|e| e.to_s}.join unless @expressions.empty?
s << @quantifier if quantified?
end
s
end
|