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.



147
148
149
# File 'lib/regexp-examples/groups.rb', line 147

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.



145
146
147
# File 'lib/regexp-examples/groups.rb', line 145

def repeaters_list
  @repeaters_list
end

Instance Method Details

#random_resultObject



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

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

#resultObject



151
152
153
# File 'lib/regexp-examples/groups.rb', line 151

def result
  result_by_method(:result)
end