Class: Cucumber::StepMatch

Inherits:
Object show all
Defined in:
lib/cucumber/step_match.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step_definition, step_name, formatted_step_name, groups) ⇒ StepMatch

Returns a new instance of StepMatch.



5
6
7
# File 'lib/cucumber/step_match.rb', line 5

def initialize(step_definition, step_name, formatted_step_name, groups)
  @step_definition, @step_name, @formatted_step_name, @groups = step_definition, step_name, formatted_step_name, groups
end

Instance Attribute Details

#step_definitionObject (readonly)

Returns the value of attribute step_definition.



3
4
5
# File 'lib/cucumber/step_match.rb', line 3

def step_definition
  @step_definition
end

Instance Method Details

#argsObject



9
10
11
# File 'lib/cucumber/step_match.rb', line 9

def args
  @groups.map{|g| g.val}
end

#backtrace_lineObject



46
47
48
# File 'lib/cucumber/step_match.rb', line 46

def backtrace_line
  @step_definition.backtrace_line
end

#file_colon_lineObject



42
43
44
# File 'lib/cucumber/step_match.rb', line 42

def file_colon_line
  @step_definition.file_colon_line
end

#format_args(format = lambda{|a| a}, &proc) ⇒ Object

Formats the matched arguments of the associated Step. This method is usually called from visitors, which render output.

The format can either be a String or a Proc.

If it is a String it should be a format string according to Kernel#sprinf, for example:

'<span class="param">%s</span></tt>'

If it is a Proc, it should take one argument and return the formatted argument, for example:

lambda { |param| "[#{param}]" }


38
39
40
# File 'lib/cucumber/step_match.rb', line 38

def format_args(format = lambda{|a| a}, &proc)
  @formatted_step_name || gzub(@step_name, @groups, format, &proc)
end

#gzub(string, groups, format = nil, &proc) ⇒ Object

groups is an array of 2-element arrays, where the 1st element is the value of a regexp match group, and the 2nd element is its start index.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cucumber/step_match.rb', line 57

def gzub(string, groups, format=nil, &proc)
  s = string.dup
  offset = 0
  groups.each do |group|
    replacement = if block_given?
      proc.call(group.val)
    elsif Proc === format
      format.call(group.val)
    else
      format % group.val
    end

    s[group.start + offset, group.val.length] = replacement
    offset += replacement.length - group.val.length
  end
  s
end

#invoke(multiline_arg) ⇒ Object



17
18
19
20
21
# File 'lib/cucumber/step_match.rb', line 17

def invoke(multiline_arg)
  all_args = args
  all_args << multiline_arg if multiline_arg
  @step_definition.invoke(all_args)
end

#nameObject



13
14
15
# File 'lib/cucumber/step_match.rb', line 13

def name
  @formatted_step_name
end

#text_lengthObject



50
51
52
# File 'lib/cucumber/step_match.rb', line 50

def text_length
  @step_definition.text_length
end