Method: Cucumber::StepMatch#replace_arguments

Defined in:
lib/cucumber/step_match.rb

#replace_arguments(string, step_arguments, format, &proc) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cucumber/step_match.rb', line 59

def replace_arguments(string, step_arguments, format, &proc)
  s = string.dup
  offset = past_offset = 0
  step_arguments.each do |step_argument|
    next if step_argument.offset.nil? || step_argument.offset < past_offset

    replacement = if block_given?
      proc.call(step_argument.val)
    elsif Proc === format
      format.call(step_argument.val)
    else
      format % step_argument.val
    end

    s[step_argument.offset + offset, step_argument.val.length] = replacement
    offset += replacement.unpack('U*').length - step_argument.val.unpack('U*').length
    past_offset = step_argument.offset + step_argument.val.length
  end
  s
end