Class: Cucumber::CucumberExpressions::ParameterType

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 6

def name
  @name
end

#regexpsObject (readonly)

Returns the value of attribute regexps.



6
7
8
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 6

def regexps
  @regexps
end

#typeObject (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



50
51
52
53
54
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 50

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(self_obj, group_values) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cucumber/cucumber_expressions/parameter_type.rb', line 37

def transform(self_obj, 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
    args = [non_nil_group_values[0]]
  else
    args = group_values
  end
  self_obj.instance_exec(*args, &@transformer)
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