Class: RegexpExamples::MultiGroup

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(groups, group_id) ⇒ MultiGroup

Returns a new instance of MultiGroup.



129
130
131
132
# File 'lib/regexp-examples/groups.rb', line 129

def initialize(groups, group_id)
  @groups = groups
  @group_id = group_id
end

Instance Attribute Details

#group_idObject (readonly)

Returns the value of attribute group_id.



128
129
130
# File 'lib/regexp-examples/groups.rb', line 128

def group_id
  @group_id
end

Instance Method Details

#resultObject Also known as: random_result

Generates the result of each contained group and adds the filled group of each result to itself



136
137
138
139
140
141
# File 'lib/regexp-examples/groups.rb', line 136

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