Sha256: 57ffe02b8ba6a8814c5f0101c1aa2c7cc9a1037c2593c8352c614f7640396a54

Contents?: true

Size: 626 Bytes

Versions: 3

Compression:

Stored size: 626 Bytes

Contents

module Gurke
  class StepDefinition
    attr_reader :pattern, :method_name, :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

3 entries across 3 versions & 1 rubygems

Version Path
gurke-2.4.2 lib/gurke/step_definition.rb
gurke-2.4.1 lib/gurke/step_definition.rb
gurke-2.4.0 lib/gurke/step_definition.rb