Class: Cucumber::CucumberExpressions::ParameterType
- Inherits:
-
Object
- Object
- Cucumber::CucumberExpressions::ParameterType
- Defined in:
- lib/cucumber/cucumber_expressions/parameter_type.rb
Constant Summary collapse
- ILLEGAL_PARAMETER_NAME_PATTERN =
/([\[\]()$.|?*+])/.freeze
- UNESCAPE_PATTERN =
/(\\([\[$.|?*+\]]))/.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prefer_for_regexp_match ⇒ Object
readonly
Returns the value of attribute prefer_for_regexp_match.
-
#regexps ⇒ Object
readonly
Returns the value of attribute regexps.
-
#transformer ⇒ Object
readonly
Returns the value of attribute transformer.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#use_for_snippets ⇒ Object
readonly
Returns the value of attribute use_for_snippets.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name, regexp, type, transformer, use_for_snippets, prefer_for_regexp_match) ⇒ ParameterType
constructor
Create a new Parameter.
- #transform(self_obj, group_values) ⇒ Object
Constructor Details
#initialize(name, regexp, type, transformer, use_for_snippets, prefer_for_regexp_match) ⇒ ParameterType
Create a new Parameter
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 31 def initialize(name, regexp, type, transformer, use_for_snippets, prefer_for_regexp_match) raise "regexp can't be nil" if regexp.nil? raise "type can't be nil" if type.nil? raise "transformer can't be nil" if transformer.nil? raise "use_for_snippets can't be nil" if use_for_snippets.nil? raise "prefer_for_regexp_match can't be nil" if prefer_for_regexp_match.nil? self.class.check_parameter_type_name(name) unless name.nil? @name, @type, @transformer, @use_for_snippets, @prefer_for_regexp_match = name, type, transformer, use_for_snippets, prefer_for_regexp_match @regexps = string_array(regexp) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 11 def name @name end |
#prefer_for_regexp_match ⇒ Object (readonly)
Returns the value of attribute prefer_for_regexp_match.
11 12 13 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 11 def prefer_for_regexp_match @prefer_for_regexp_match end |
#regexps ⇒ Object (readonly)
Returns the value of attribute regexps.
11 12 13 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 11 def regexps @regexps end |
#transformer ⇒ Object (readonly)
Returns the value of attribute transformer.
11 12 13 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 11 def transformer @transformer end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 11 def type @type end |
#use_for_snippets ⇒ Object (readonly)
Returns the value of attribute use_for_snippets.
11 12 13 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 11 def use_for_snippets @use_for_snippets end |
Class Method Details
.check_parameter_type_name(type_name) ⇒ Object
13 14 15 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 13 def self.check_parameter_type_name(type_name) raise CucumberExpressionError.new("Illegal character in parameter name {#{type_name}}. Parameter names may not contain '[]()$.|?*+'") unless is_valid_parameter_type_name(type_name) end |
.is_valid_parameter_type_name(type_name) ⇒ Object
17 18 19 20 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 17 def self.is_valid_parameter_type_name(type_name) unescaped_type_name = type_name.gsub(UNESCAPE_PATTERN) { Regexp.last_match(2) } !(ILLEGAL_PARAMETER_NAME_PATTERN =~ unescaped_type_name) end |
Instance Method Details
#<=>(other) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 47 def <=>(other) return -1 if prefer_for_regexp_match && !other.prefer_for_regexp_match return 1 if other.prefer_for_regexp_match && !prefer_for_regexp_match return name <=> other.name end |
#transform(self_obj, group_values) ⇒ Object
43 44 45 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 43 def transform(self_obj, group_values) self_obj.instance_exec(*group_values, &@transformer) end |