Class: RegexpExamples::MultiGroup
- Inherits:
-
Object
- Object
- RegexpExamples::MultiGroup
- Defined in:
- lib/regexp-examples/groups.rb
Overview
A collection of other groups. Basically any regex that contains brackets will be parsed using one of these. The simplest example is: /(a)/ - Which is a MultiGroup, containing one SingleCharGroup
Instance Attribute Summary collapse
-
#group_id ⇒ Object
readonly
Returns the value of attribute group_id.
Instance Method Summary collapse
-
#initialize(groups, group_id) ⇒ MultiGroup
constructor
A new instance of MultiGroup.
-
#result ⇒ Object
(also: #random_result)
Generates the result of each contained group and adds the filled group of each result to itself.
Constructor Details
#initialize(groups, group_id) ⇒ MultiGroup
Returns a new instance of MultiGroup.
120 121 122 123 |
# File 'lib/regexp-examples/groups.rb', line 120 def initialize(groups, group_id) @groups = groups @group_id = group_id end |
Instance Attribute Details
#group_id ⇒ Object (readonly)
Returns the value of attribute group_id.
119 120 121 |
# File 'lib/regexp-examples/groups.rb', line 119 def group_id @group_id end |
Instance Method Details
#result ⇒ Object Also known as: random_result
Generates the result of each contained group and adds the filled group of each result to itself
127 128 129 130 131 132 |
# File 'lib/regexp-examples/groups.rb', line 127 def result strings = @groups.map { |repeater| repeater.public_send(__method__) } RegexpExamples.permutations_of_strings(strings).map do |result| GroupResult.new(result, group_id) end end |