Class: Cucumber::JsSupport::JsTransform

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/js_support/js_language.rb

Instance Method Summary collapse

Constructor Details

#initialize(js_language, regexp, js_function) ⇒ JsTransform

Returns a new instance of JsTransform.



76
77
78
# File 'lib/cucumber/js_support/js_language.rb', line 76

def initialize(js_language, regexp, js_function)
  @js_language, @regexp, @js_function = js_language, regexp.to_s, js_function
end

Instance Method Details

#invoke(arg) ⇒ Object



86
87
88
# File 'lib/cucumber/js_support/js_language.rb', line 86

def invoke(arg)
  @js_function.call([arg])
end

#match(arg) ⇒ Object



80
81
82
83
84
# File 'lib/cucumber/js_support/js_language.rb', line 80

def match(arg)
  arg = JsSupport.argument_safe_string(arg)
  matches = (eval_js "#{@regexp}.exec('#{arg}');").to_a
  matches.empty? ? nil : matches[1..-1]
end