module Arugula::MatchNTimes

Public Class Methods

new(*args, times: 1..1) click to toggle source
Calls superclass method Arugula::Wrapping::new
# File lib/arugula/parts.rb, line 210
def initialize(*args, times: 1..1)
  @times = times
  super(*args)
end

Public Instance Methods

match(str, index, match_data) click to toggle source
# File lib/arugula/parts.rb, line 215
def match(str, index, match_data)
  match_count = 0
  end_index = index

  loop do
    matches, index = wrapped.match(str, index, match_data)
    if matches
      end_index = index
      match_count += 1
    end
    break if !matches || match_count > @times.end
  end

  matches = @times.member?(match_count)
  [matches, matches ? end_index : index]
end