Sha256: 3c761b39f24fb663f11bc4eba20a28c5f91ad1946e82f7d83e10dfbfc7263b6e

Contents?: true

Size: 643 Bytes

Versions: 9

Compression:

Stored size: 643 Bytes

Contents

# frozen_string_literal: true

module Gurke
  class StepDefinition
    attr_reader :pattern, :opts

    def initialize(pattern, opts = {})
      @pattern      = pattern
      @opts         = opts
    end

    def method_name
      "#{type.to_s.capitalize} #{pattern}"
    end

    def type
      opts[:type] || :any
    end

    def match(name, type = :any)
      return if self.type != :any && self.type != type
      return if pattern.is_a?(String) && name != pattern
      match = pattern.match(name)

      return unless match

      Match.new method_name, match.to_a[1..-1]
    end

    Match = Struct.new :method_name, :params
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gurke-3.3.4 lib/gurke/step_definition.rb
gurke-3.3.3 lib/gurke/step_definition.rb
gurke-3.3.2 lib/gurke/step_definition.rb
gurke-3.3.1 lib/gurke/step_definition.rb
gurke-3.2.2 lib/gurke/step_definition.rb
gurke-3.2.1 lib/gurke/step_definition.rb
gurke-3.2.0 lib/gurke/step_definition.rb
gurke-3.1.0 lib/gurke/step_definition.rb
gurke-3.0.0 lib/gurke/step_definition.rb