Sha256: c487f6fcb9d82416109e3479bce8d226003b3673b8310787926555d46eceb969

Contents?: true

Size: 1.16 KB

Versions: 43

Compression:

Stored size: 1.16 KB

Contents

require 'cucumber/cucumber_expressions/group'
require 'cucumber/cucumber_expressions/errors'

module Cucumber
  module CucumberExpressions
    class Argument
      attr_reader :group, :parameter_type

      def self.build(tree_regexp, text, parameter_types)
        group = tree_regexp.match(text)
        return nil if group.nil?

        arg_groups = group.children

        if arg_groups.length != parameter_types.length
          raise CucumberExpressionError.new(
              "Expression #{tree_regexp.regexp.inspect} has #{arg_groups.length} capture groups (#{arg_groups.map(&:value)}), but there were #{parameter_types.length} parameter types (#{parameter_types.map(&:name)})"
          )
        end

        parameter_types.zip(arg_groups).map do |parameter_type, arg_group|
          Argument.new(arg_group, parameter_type)
        end
      end

      def initialize(group, parameter_type)
        @group, @parameter_type = group, parameter_type
      end

      def value(self_obj=:nil)
        raise "No self_obj" if self_obj == :nil
        group_values = @group ? @group.values : nil
        @parameter_type.transform(self_obj, group_values)
      end
    end
  end
end

Version data entries

43 entries across 43 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/argument.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/argument.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/argument.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/argument.rb
cucumber-cucumber-expressions-16.1.2 lib/cucumber/cucumber_expressions/argument.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/argument.rb
cucumber-cucumber-expressions-16.1.1 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-16.1.0 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-16.0.1 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-16.0.0 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-15.2.0 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-15.1.1 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-15.1.0 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-15.0.2 lib/cucumber/cucumber_expressions/argument.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-cucumber-expressions-14.0.0/lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-15.0.1 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-14.0.0 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-13.1.3 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-13.1.2 lib/cucumber/cucumber_expressions/argument.rb
cucumber-cucumber-expressions-13.1.1 lib/cucumber/cucumber_expressions/argument.rb