Sha256: 3b1fe386ac72beceedfdb2b8b6365814ebdbc7aae79e230f5057b6a0c6841068

Contents?: true

Size: 1.2 KB

Versions: 50

Compression:

Stored size: 1.2 KB

Contents

require 'cucumber/cucumber_expressions/argument'
require 'cucumber/cucumber_expressions/parameter_type'
require 'cucumber/cucumber_expressions/tree_regexp'

module Cucumber
  module CucumberExpressions
    class RegularExpression

      def initialize(expression_regexp, parameter_type_registry)
        @expression_regexp = expression_regexp
        @parameter_type_registry = parameter_type_registry
        @tree_regexp = TreeRegexp.new(@expression_regexp)
      end

      def match(text)
        parameter_types = @tree_regexp.group_builder.children.map do |group_builder|
          parameter_type_regexp = group_builder.source
          @parameter_type_registry.lookup_by_regexp(
            parameter_type_regexp,
            @expression_regexp,
            text
          ) || ParameterType.new(
            nil,
            parameter_type_regexp,
            String,
            lambda {|*s| s[0]},
            false,
            false
          )
        end

        Argument.build(@tree_regexp, text, parameter_types)
      end

      def regexp
        @expression_regexp
      end

      def source
        @expression_regexp.source
      end

      def to_s
        regexp.inspect
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 5 rubygems

Version Path
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-cucumber-expressions-16.1.2/lib/cucumber/cucumber_expressions/regular_expression.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/lib/cucumber/cucumber_expressions/regular_expression.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/lib/cucumber/cucumber_expressions/regular_expression.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-16.1.2 lib/cucumber/cucumber_expressions/regular_expression.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-16.1.1 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-16.1.0 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-16.0.1 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-16.0.0 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-15.2.0 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-15.1.1 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-15.1.0 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-15.0.2 lib/cucumber/cucumber_expressions/regular_expression.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-cucumber-expressions-14.0.0/lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-15.0.1 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-14.0.0 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-13.1.3 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-13.1.2 lib/cucumber/cucumber_expressions/regular_expression.rb
cucumber-cucumber-expressions-13.1.1 lib/cucumber/cucumber_expressions/regular_expression.rb