Class: Cucumber::CucumberExpressions::CucumberExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/cucumber_expressions/cucumber_expression.rb

Constant Summary collapse

ESCAPE_REGEXP =

Does not include (){} characters because they have special meaning

/([\\^\[$.|?*+\]])/
PARAMETER_REGEXP =
/(\\\\)?{([^}]*)}/
OPTIONAL_REGEXP =
/(\\\\)?\(([^)]+)\)/
ALTERNATIVE_NON_WHITESPACE_TEXT_REGEXP =
/([^\s^\/]+)((\/[^\s^\/]+)+)/
DOUBLE_ESCAPE =
'\\\\'
PARAMETER_TYPES_CANNOT_BE_ALTERNATIVE =
'Parameter types cannot be alternative: '
PARAMETER_TYPES_CANNOT_BE_OPTIONAL =
'Parameter types cannot be optional: '

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression, parameter_type_registry) ⇒ CucumberExpression

Returns a new instance of CucumberExpression.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cucumber/cucumber_expressions/cucumber_expression.rb', line 19

def initialize(expression, parameter_type_registry)
  @source = expression
  @parameter_types = []

  expression = process_escapes(expression)
  expression = process_optional(expression)
  expression = process_alternation(expression)
  expression = process_parameters(expression, parameter_type_registry)
  expression = "^#{expression}$"

  @tree_regexp = TreeRegexp.new(expression)
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



17
18
19
# File 'lib/cucumber/cucumber_expressions/cucumber_expression.rb', line 17

def source
  @source
end

Instance Method Details

#match(text) ⇒ Object



32
33
34
# File 'lib/cucumber/cucumber_expressions/cucumber_expression.rb', line 32

def match(text)
  Argument.build(@tree_regexp, text, @parameter_types)
end

#regexpObject



36
37
38
# File 'lib/cucumber/cucumber_expressions/cucumber_expression.rb', line 36

def regexp
  @tree_regexp.regexp
end

#to_sObject



40
41
42
# File 'lib/cucumber/cucumber_expressions/cucumber_expression.rb', line 40

def to_s
  @source.inspect
end