Class: RegexpExamples::BaseRepeater
- Inherits:
-
Object
- Object
- RegexpExamples::BaseRepeater
- Defined in:
- lib/regexp-examples/repeaters.rb
Direct Known Subclasses
OneTimeRepeater, PlusRepeater, QuestionMarkRepeater, RangeRepeater, StarRepeater
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
Instance Method Summary collapse
-
#initialize(group) ⇒ BaseRepeater
constructor
A new instance of BaseRepeater.
- #result(min_repeats, max_repeats) ⇒ Object
Constructor Details
#initialize(group) ⇒ BaseRepeater
Returns a new instance of BaseRepeater.
4 5 6 |
# File 'lib/regexp-examples/repeaters.rb', line 4 def initialize(group) @group = group end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
3 4 5 |
# File 'lib/regexp-examples/repeaters.rb', line 3 def group @group end |
Instance Method Details
#result(min_repeats, max_repeats) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/regexp-examples/repeaters.rb', line 8 def result(min_repeats, max_repeats) group_results = @group.result[0 .. RegexpExamples.MaxGroupResults-1] results = [] min_repeats.upto(max_repeats) do |repeats| if repeats.zero? results << [ GroupResult.new('') ] else results << RegexpExamples.permutations_of_strings( [group_results] * repeats ) end end results.flatten.uniq end |