Class: RegexpExamples::GroupResult
- Inherits:
-
String
- Object
- String
- RegexpExamples::GroupResult
- Defined in:
- lib/regexp-examples/groups.rb
Overview
All Group#result methods return an array of GroupResult objects The key objective here is to keep track of all capture groups, in order to fill in backreferences
Instance Attribute Summary collapse
-
#group_id ⇒ Object
readonly
Returns the value of attribute group_id.
-
#subgroups ⇒ Object
readonly
Returns the value of attribute subgroups.
Instance Method Summary collapse
- #all_subgroups ⇒ Object
-
#initialize(result, group_id = nil, subgroups = []) ⇒ GroupResult
constructor
A new instance of GroupResult.
- #swapcase ⇒ Object
Constructor Details
#initialize(result, group_id = nil, subgroups = []) ⇒ GroupResult
Returns a new instance of GroupResult.
7 8 9 10 11 |
# File 'lib/regexp-examples/groups.rb', line 7 def initialize(result, group_id = nil, subgroups = []) @group_id = group_id @subgroups = result.respond_to?(:group_id) ? result.all_subgroups : subgroups super(result) end |
Instance Attribute Details
#group_id ⇒ Object (readonly)
Returns the value of attribute group_id.
6 7 8 |
# File 'lib/regexp-examples/groups.rb', line 6 def group_id @group_id end |
#subgroups ⇒ Object (readonly)
Returns the value of attribute subgroups.
6 7 8 |
# File 'lib/regexp-examples/groups.rb', line 6 def subgroups @subgroups end |
Instance Method Details
#all_subgroups ⇒ Object
13 14 15 |
# File 'lib/regexp-examples/groups.rb', line 13 def all_subgroups [self, subgroups].flatten.keep_if(&:group_id) end |
#swapcase ⇒ Object
17 18 19 20 |
# File 'lib/regexp-examples/groups.rb', line 17 def swapcase # Override to preserve subgroups GroupResult.new(super.to_s, group_id, subgroups) end |