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.



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

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.



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

def repeaters_list
  @repeaters_list
end

Instance Method Details

#random_resultObject



173
174
175
# File 'lib/regexp-examples/groups.rb', line 173

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

#resultObject



169
170
171
# File 'lib/regexp-examples/groups.rb', line 169

def result
  result_by_method(:map_results)
end