Class: Gurke::StepDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/gurke/step_definition.rb

Defined Under Namespace

Classes: Match

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, opts = {}) ⇒ StepDefinition

Returns a new instance of StepDefinition.



7
8
9
10
# File 'lib/gurke/step_definition.rb', line 7

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

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



5
6
7
# File 'lib/gurke/step_definition.rb', line 5

def opts
  @opts
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/gurke/step_definition.rb', line 5

def pattern
  @pattern
end

Instance Method Details

#match(name, type = :any) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/gurke/step_definition.rb', line 20

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..]
end

#method_nameObject



12
13
14
# File 'lib/gurke/step_definition.rb', line 12

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

#typeObject



16
17
18
# File 'lib/gurke/step_definition.rb', line 16

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