Class: RegexpExamples::OrGroup
- Inherits:
-
Object
- Object
- RegexpExamples::OrGroup
- Defined in:
- lib/regexp-examples/groups.rb
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.
135 136 137 138 |
# File 'lib/regexp-examples/groups.rb', line 135 def initialize(left_repeaters, right_repeaters) @left_repeaters = left_repeaters @right_repeaters = right_repeaters end |
Instance Method Details
#random_result ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/regexp-examples/groups.rb', line 144 def random_result # TODO: This logic is flawed in terms of choosing a truly "random" example! # E.g. /a|b|c|d/.random_example will choose a letter with the following probabilities: # a = 50%, b = 25%, c = 12.5%, d = 12.5% # In order to fix this, I must either apply some weighted selection logic, # or change how the OrGroup examples are generated - i.e. make this class work with >2 repeaters result_by_method(:map_random_result).sample(1) end |
#result ⇒ Object
140 141 142 |
# File 'lib/regexp-examples/groups.rb', line 140 def result result_by_method(:map_results) end |