Class: RegexpExamples::RangeRepeater

Inherits:
BaseRepeater show all
Defined in:
lib/regexp-examples/repeaters.rb

Instance Attribute Summary

Attributes inherited from BaseRepeater

#group, #max_repeats, #min_repeats

Instance Method Summary collapse

Methods inherited from BaseRepeater

#random_result, #result

Constructor Details

#initialize(group, min, has_comma, max) ⇒ RangeRepeater

Returns a new instance of RangeRepeater.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/regexp-examples/repeaters.rb', line 64

def initialize(group, min, has_comma, max)
  super(group)
  @min_repeats = min || 0
  if max # e.g. {1,100} --> Treat as {1,3} or similar, to prevent a huge number of results
    @max_repeats = smallest(max, @min_repeats + RegexpExamples.MaxRepeaterVariance)
  elsif has_comma # e.g. {2,} --> Treat as {2,4} or similar
    @max_repeats = @min_repeats + RegexpExamples.MaxRepeaterVariance
  else # e.g. {3} --> Treat as {3,3}
    @max_repeats = @min_repeats
  end
end