Sha256: 2f3ea1cdfc882ef83a1a92a211e3c5dbfd2ef5c9dc25fba9331c1be5c5619d9b

Contents?: true

Size: 759 Bytes

Versions: 1

Compression:

Stored size: 759 Bytes

Contents

# frozen_string_literal: true
class Arugula
  require 'arugula/version'

  attr_reader :captures

  autoload :MatchData, 'arugula/match_data'
  autoload :Parser, 'arugula/parser'

  def initialize(pattern)
    @root, @captures = Parser.new(pattern).parse!
  end

  def match?(str, index = 0)
    match_data = match(str, index)
    match_data && match_data.start_index
  end

  def match(str, index = 0)
    match_data = MatchData.new(self, str)
    loop do
      match, end_index = @root.match(str, index, match_data)
      if match
        match_data.start_index = index
        match_data.end_index = end_index
        return match_data.freeze
      end
      index += 1
      return if index > str.size
    end
  end

  def to_s
    "/#{@root}/"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arugula-0.3.0 lib/arugula.rb