Class: RegexpExamples::RangeRepeater

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

Instance Attribute Summary

Attributes inherited from BaseRepeater

#group

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RangeRepeater.



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

def initialize(group, min, has_comma, max)
  super(group)
  @min = min || 0
  if max
    # Prevent huge number of results in case of e.g. /.{1,100}/.examples
    @max = smallest(max, @min + RegexpExamples.MaxRepeaterVariance)
  elsif has_comma
    @max = @min + RegexpExamples.MaxRepeaterVariance
  else
    @max = @min
  end
end

Instance Method Details

#resultObject



78
79
80
# File 'lib/regexp-examples/repeaters.rb', line 78

def result
  super(@min, @max)
end