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.



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_idObject (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

#resultObject 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