Class: RegexpExamples::OrGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/regexp-examples/groups.rb

Instance Method Summary collapse

Constructor Details

#initialize(left_repeaters, right_repeaters) ⇒ OrGroup

Returns a new instance of OrGroup.



127
128
129
130
# File 'lib/regexp-examples/groups.rb', line 127

def initialize(left_repeaters, right_repeaters)
  @left_repeaters = left_repeaters
  @right_repeaters = right_repeaters
end

Instance Method Details

#random_resultObject



136
137
138
139
140
141
142
143
# File 'lib/regexp-examples/groups.rb', line 136

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

#resultObject



132
133
134
# File 'lib/regexp-examples/groups.rb', line 132

def result
  result_by_method(:map_results)
end