A Ruby Transform holds a Regexp and a Proc, and is created by calling
Transform in the <tt>support
ruby files. See also RbDsl.
Example:
Transform %r^(\d+) cucumbers$/ do |cucumbers_string| cucumbers_string.to_i end
# File lib/cucumber/rb_support/rb_transform.rb, line 20 def initialize(rb_language, pattern, proc) raise MissingProc if proc.nil? || proc.arity < 1 @rb_language, @regexp, @proc = rb_language, Regexp.new(pattern), proc end
# File lib/cucumber/rb_support/rb_transform.rb, line 29 def invoke(arg) if matched = match(arg) args = matched.captures.empty? ? [arg] : matched.captures @rb_language.current_world.cucumber_instance_exec(true, @regexp.inspect, *args, &@proc) end end
# File lib/cucumber/rb_support/rb_transform.rb, line 25 def match(arg) arg ? arg.match(@regexp) : nil end
# File lib/cucumber/rb_support/rb_transform.rb, line 36 def to_s convert_captures(strip_anchors(@regexp.source)) end