Class: Cucumber::RbSupport::RbTransform
- Inherits:
-
Object
- Object
- Cucumber::RbSupport::RbTransform
- Defined in:
- lib/cucumber/rb_support/rb_transform.rb
Overview
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 /^(\d+) cucumbers$/ do |cucumbers_string|
cucumbers_string.to_i
end
Defined Under Namespace
Classes: MissingProc
Instance Method Summary (collapse)
-
- (RbTransform) initialize(rb_language, pattern, proc)
constructor
A new instance of RbTransform.
- - (Object) invoke(arg)
- - (Object) match(arg)
- - (Object) to_s
Constructor Details
- (RbTransform) initialize(rb_language, pattern, proc)
A new instance of RbTransform
20 21 22 23 |
# 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 |
Instance Method Details
- (Object) invoke(arg)
29 30 31 32 33 34 |
# 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 |
- (Object) match(arg)
25 26 27 |
# File 'lib/cucumber/rb_support/rb_transform.rb', line 25 def match(arg) arg ? arg.match(@regexp) : nil end |
- (Object) to_s
36 37 38 |
# File 'lib/cucumber/rb_support/rb_transform.rb', line 36 def to_s convert_captures(strip_anchors(@regexp.source)) end |