Class: RegexpExamples::OrGroup
- Inherits:
-
Object
- Object
- RegexpExamples::OrGroup
- 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
-
#repeaters_list ⇒ Object
readonly
Returns the value of attribute repeaters_list.
Instance Method Summary collapse
-
#initialize(left_repeaters, right_repeaters) ⇒ OrGroup
constructor
A new instance of OrGroup.
- #random_result ⇒ Object
- #result ⇒ Object
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_list ⇒ Object (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_result ⇒ Object
155 156 157 |
# File 'lib/regexp-examples/groups.rb', line 155 def random_result result_by_method(:random_result).sample(1) end |
#result ⇒ Object
151 152 153 |
# File 'lib/regexp-examples/groups.rb', line 151 def result result_by_method(:result) end |