class RegexpExamples::BaseRepeater
An abstract base class for all other repeater groups. Since all repeaters (quantifiers) are really just shorthand syntaxes for the generic: ‘/.{a,b}/`, the methods for generating “between `a` and `b` results” are fully generalised here.
Attributes
group[R]
max_repeats[R]
min_repeats[R]
Public Class Methods
new(group)
click to toggle source
# File lib/regexp-examples/repeaters.rb, line 8 def initialize(group) @group = group end
Public Instance Methods
random_result()
click to toggle source
# File lib/regexp-examples/repeaters.rb, line 29 def random_result result = [] rand(min_repeats..max_repeats).times { result << group.random_result } result << [GroupResult.new('')] if result.empty? # in case of 0.times RegexpExamples.permutations_of_strings(result) end
result()
click to toggle source
# File lib/regexp-examples/repeaters.rb, line 12 def result group_results = group.result.first(RegexpExamples::Config.max_group_results) results = [] max_results_limiter = MaxResultsLimiterBySum.new min_repeats.upto(max_repeats) do |repeats| result = if repeats.zero? [GroupResult.new('')] else RegexpExamples.permutations_of_strings( [group_results] * repeats ) end results << max_results_limiter.limit_results(result) end results.flatten.uniq end