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.
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_list ⇒ Object (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_result ⇒ Object
164 165 166 |
# File 'lib/regexp-examples/groups.rb', line 164 def random_result result_by_method(:map_random_result).sample(1) end |
#result ⇒ Object
160 161 162 |
# File 'lib/regexp-examples/groups.rb', line 160 def result result_by_method(:map_results) end |