Skip to content

Commit b5582d9

Browse files
committed
Simplify method and remove unnecessary helper
1 parent 2b1ad1d commit b5582d9

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

lib/regexp-examples/repeaters.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,14 @@ class RangeRepeater < BaseRepeater
8080
def initialize(group, min, has_comma, max)
8181
super(group)
8282
@min_repeats = min || 0
83-
if max # e.g. {1,100} --> Treat as {1,3} (by default max_repeater_variance)
84-
@max_repeats = smallest(
85-
max, @min_repeats + RegexpExamples::Config.max_repeater_variance
86-
)
87-
elsif has_comma # e.g. {2,} --> Treat as {2,4} (by default max_repeater_variance)
88-
@max_repeats = @min_repeats + RegexpExamples::Config.max_repeater_variance
89-
else # e.g. {3} --> Treat as {3,3}
90-
@max_repeats = @min_repeats
91-
end
92-
end
93-
94-
private
95-
96-
def smallest(x, y)
97-
x < y ? x : y
83+
@max_repeats = if !has_comma
84+
@min_repeats
85+
else
86+
[
87+
max,
88+
@min_repeats + RegexpExamples::Config.max_repeater_variance
89+
].compact.min
90+
end
9891
end
9992
end
10093
end

0 commit comments

Comments
 (0)