Sha256: 22d2d03febbc19e79bdff953e4162c843a20ff320a335b3bb2364f42095a361b

Contents?: true

Size: 848 Bytes

Versions: 2

Compression:

Stored size: 848 Bytes

Contents

module Cucumber
  module CucumberExpressions
    class ParameterMatcher
      attr_reader :parameter

      def initialize(parameter, regexp, text, match_position=0)
        @parameter, @regexp, @text = parameter, regexp, text
        @match = @regexp.match(@text, match_position)
      end

      def advance_to(new_match_position)
        self.class.new(parameter, @regexp, @text, new_match_position)
      end

      def find
        !@match.nil?
      end

      def start
        @match.begin(0)
      end

      def group
        @match.captures[0]
      end

      def <=>(other)
        pos_comparison = start <=> other.start
        return pos_comparison if pos_comparison != 0
        length_comparison = other.group.length <=> group.length
        return length_comparison if length_comparison != 0
        0
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cucumber-expressions-2.0.1 lib/cucumber/cucumber_expressions/parameter_matcher.rb
cucumber-expressions-2.0.0 lib/cucumber/cucumber_expressions/parameter_matcher.rb