Class: Regexp::Expression::Conditional::Expression
Instance Attribute Summary collapse
#expressions
Attributes inherited from Base
#conditional_level, #level, #nesting_level, #options, #quantifier, #set_level, #text, #token, #ts, #type
Instance Method Summary
collapse
#dig, #each_expression, #flat_map, #initialize, #initialize_clone, #inner_match_length, #match_length, #strfregexp_tree, #te, #to_h, #traverse
Methods inherited from Base
#ascii_classes?, #attributes, #case_insensitive?, #coded_offset, #default_classes?, #free_spacing?, #full_length, #greedy?, #initialize, #initialize_clone, #is?, #match, #match?, #multiline?, #offset, #one_of?, #possessive?, #quantified?, #quantifier_affix, #quantify, #quantity, #reluctant?, #repetitions, #strfregexp, #terminal?, #to_re, #type?, #unicode_classes?, #unquantified_clone
Instance Attribute Details
#referenced_expression ⇒ Object
Returns the value of attribute referenced_expression.
23
24
25
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 23
def referenced_expression
@referenced_expression
end
|
Instance Method Details
#<<(exp) ⇒ Object
25
26
27
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 25
def <<(exp)
expressions.last << exp
end
|
#add_sequence(active_opts = {}) ⇒ Object
Also known as:
branch
29
30
31
32
33
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 29
def add_sequence(active_opts = {})
raise TooManyBranches.new if branches.length == 2
params = { conditional_level: conditional_level + 1 }
Branch.add_to(self, params, active_opts)
end
|
#branches ⇒ Object
45
46
47
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 45
def branches
select { |subexp| subexp.is_a?(Sequence) }
end
|
#condition ⇒ Object
41
42
43
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 41
def condition
find { |subexp| subexp.is_a?(Condition) }
end
|
#condition=(exp) ⇒ Object
36
37
38
39
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 36
def condition=(exp)
expressions.delete(condition)
expressions.unshift(exp)
end
|
#reference ⇒ Object
49
50
51
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 49
def reference
condition.reference
end
|
#to_s(format = :full) ⇒ Object
53
54
55
|
# File 'lib/regexp_parser/expression/classes/conditional.rb', line 53
def to_s(format = :full)
"#{text}#{condition}#{branches.join('|')})#{quantifier_affix(format)}"
end
|