Class: RegexpExamples::OrGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/regexp-examples/groups.rb

Overview

A boolean “or” group. The implementation is to pass in 2 set of (repeaters of) groups. The simplest example is: /a|b/ If you have more than one boolean “or” operator, then this is initially parsed as an OrGroup containing another OrGroup. However, in order to avoid probability distribution issues in Regexp#random_example, this then gets simplified down to one OrGroup containing 3+ repeaters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left_repeaters, right_repeaters) ⇒ OrGroup

Returns a new instance of OrGroup.



156
157
158
# File 'lib/regexp-examples/groups.rb', line 156

def initialize(left_repeaters, right_repeaters)
  @repeaters_list = [left_repeaters, *merge_if_orgroup(right_repeaters)]
end

Instance Attribute Details

#repeaters_listObject (readonly)

Returns the value of attribute repeaters_list.



154
155
156
# File 'lib/regexp-examples/groups.rb', line 154

def repeaters_list
  @repeaters_list
end

Instance Method Details

#random_resultObject



164
165
166
# File 'lib/regexp-examples/groups.rb', line 164

def random_result
  result_by_method(:map_random_result).sample(1)
end

#resultObject



160
161
162
# File 'lib/regexp-examples/groups.rb', line 160

def result
  result_by_method(:map_results)
end