4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-ci-environment-9.1.0/lib/cucumber/ci_environment/variable_expression.rb', line 4
def evaluate(expression, env)
return nil if expression.nil?
begin
expression.gsub(/\${(.*?)(?:(?<!\\)\/(.*)\/(.*))?}/) do
variable = $1
pattern = $2
replacement = $3
value = get_value(variable, env)
raise "Undefined variable #{variable}" if value.nil?
if pattern.nil?
value
else
regexp = Regexp.new(pattern.gsub('\/', '/'))
match = value.match(regexp)
raise "No match for variable #{variable}" if match.nil?
match[1..-1].each_with_index do |group, i|
replacement = replacement.gsub("\\#{i+1}", group)
end
replacement
end
end
rescue
nil
end
end
|