Class: Cucumber::CucumberExpressions::CucumberExpression
- Inherits:
-
Object
- Object
- Cucumber::CucumberExpressions::CucumberExpression
- Defined in:
- lib/cucumber/cucumber_expressions/cucumber_expression.rb
Constant Summary collapse
- PARAMETER_PATTERN =
/\{([^}:]+)(:([^}]+))?}/- OPTIONAL_PATTERN =
/\(([^\)]+)\)/
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(expression, types, transform_lookup) ⇒ CucumberExpression
constructor
A new instance of CucumberExpression.
- #match(text) ⇒ Object
Constructor Details
#initialize(expression, types, transform_lookup) ⇒ CucumberExpression
Returns a new instance of CucumberExpression.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cucumber/cucumber_expressions/cucumber_expression.rb', line 12 def initialize(expression, types, transform_lookup) @source = expression @transforms = [] regexp = "^" type_index = 0 match = nil match_offset = 0 # Create non-capturing, optional capture groups from parenthesis expression = expression.gsub(OPTIONAL_PATTERN, '(?:\1)?') loop do match = PARAMETER_PATTERN.match(expression, match_offset) break if match.nil? parameter_name = match[1] type_name = match[3] type = types.length <= type_index ? nil : types[type_index] type_index += 1 transform = nil if (type) transform = transform_lookup.lookup_by_type(type) end if (transform.nil? && type_name) transform = transform_lookup.lookup_by_type_name(type_name, false) end if (transform.nil?) transform = transform_lookup.lookup_by_type_name(parameter_name, true) end if (transform.nil?) transform = transform_lookup.create_anonymous_lookup(lambda {|s| s}) end @transforms.push(transform) text = expression.slice(match_offset...match.offset(0)[0]) capture_regexp = "(#{transform.capture_group_regexps[0]})" match_offset = match.offset(0)[1] regexp += text regexp += capture_regexp end regexp += expression.slice(match_offset..-1) regexp += "$" @regexp = Regexp.new(regexp) end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/cucumber/cucumber_expressions/cucumber_expression.rb', line 10 def source @source end |
Instance Method Details
#match(text) ⇒ Object
58 59 60 |
# File 'lib/cucumber/cucumber_expressions/cucumber_expression.rb', line 58 def match(text) ArgumentMatcher.match_arguments(@regexp, text, @transforms) end |