Class: Cucumber::CucumberExpressions::ParameterType
- Inherits:
-
Object
- Object
- Cucumber::CucumberExpressions::ParameterType
- Defined in:
- lib/cucumber/cucumber_expressions/parameter_type.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#regexps ⇒ Object
readonly
Returns the value of attribute regexps.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name, regexp, type, transformer, use_for_snippets, prefer_for_regexp_match) ⇒ ParameterType
constructor
Create a new Parameter.
- #prefer_for_regexp_match? ⇒ Boolean
- #transform(group_values) ⇒ Object
- #use_for_snippets? ⇒ Boolean
Constructor Details
#initialize(name, regexp, type, transformer, use_for_snippets, prefer_for_regexp_match) ⇒ ParameterType
Create a new Parameter
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 25 def initialize(name, regexp, type, transformer, use_for_snippets, prefer_for_regexp_match) raise "name can't be nil" if name.nil? 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? @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.
6 7 8 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 6 def name @name end |
#regexps ⇒ Object (readonly)
Returns the value of attribute regexps.
6 7 8 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 6 def regexps @regexps end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 6 def type @type end |
Instance Method Details
#<=>(other) ⇒ Object
48 49 50 51 52 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 48 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? name <=> other.name end |
#prefer_for_regexp_match? ⇒ Boolean
8 9 10 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 8 def prefer_for_regexp_match? @prefer_for_regexp_match end |
#transform(group_values) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 37 def transform(group_values) if @transformer.arity == 1 non_nil_group_values = group_values.compact raise CucumberExpressionError.new( "Single transformer unexpectedly matched 2 values - \"#{non_nil_group_values[0]}\" and \"${non_nil_group_values[1]}\"" ) if non_nil_group_values.length >= 2 return @transformer.call(non_nil_group_values[0]) end @transformer.call(*group_values) end |
#use_for_snippets? ⇒ Boolean
12 13 14 |
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 12 def use_for_snippets? @use_for_snippets end |