Class: 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 Attribute Summary collapse
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
Instance Method Summary collapse
-
#initialize(rb_language, pattern, proc) ⇒ RbTransform
constructor
A new instance of RbTransform.
- #invoke(arg) ⇒ Object
Constructor Details
#initialize(rb_language, pattern, proc) ⇒ RbTransform
Returns a new instance of RbTransform.
22 23 24 25 |
# File 'lib/cucumber/rb_support/rb_transform.rb', line 22 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 Attribute Details
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
20 21 22 |
# File 'lib/cucumber/rb_support/rb_transform.rb', line 20 def proc @proc end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
20 21 22 |
# File 'lib/cucumber/rb_support/rb_transform.rb', line 20 def regexp @regexp end |
Instance Method Details
#invoke(arg) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/cucumber/rb_support/rb_transform.rb', line 27 def invoke(arg) if matched = regexp.match(arg) args = Array(matched.captures.empty? ? arg : matched.captures) @rb_language.current_world.cucumber_instance_exec(true, regexp.inspect, *args, &@proc) end end |