Class: Cucumber::CucumberExpressions::ParameterTypeMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameter_type, regexp, text, match_position = 0) ⇒ ParameterTypeMatcher

Returns a new instance of ParameterTypeMatcher.



8
9
10
11
# File 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb', line 8

def initialize(parameter_type, regexp, text, match_position = 0)
  @parameter_type, @regexp, @text = parameter_type, regexp, text
  @match = @regexp.match(@text, match_position)
end

Instance Attribute Details

#parameter_typeObject (readonly)

Returns the value of attribute parameter_type.



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

def parameter_type
  @parameter_type
end

Instance Method Details

#<=>(other) ⇒ Object



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

def <=>(other)
  pos_comparison = start <=> other.start
  return pos_comparison if pos_comparison != 0

  length_comparison = other.group.length <=> group.length
  return length_comparison if length_comparison != 0

  0
end

#advance_to(new_match_position) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb', line 13

def advance_to(new_match_position)
  (new_match_position...@text.length).each do |advanced_position|
    matcher = self.class.new(parameter_type, @regexp, @text, advanced_position)
    return matcher if matcher.find && matcher.full_word?
  end

  self.class.new(parameter_type, @regexp, @text, @text.length)
end

#findObject



22
23
24
# File 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb', line 22

def find
  !@match.nil? && !group.empty?
end

#full_word?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb', line 26

def full_word?
  space_before_match_or_sentence_start? && space_after_match_or_sentence_end?
end

#groupObject



34
35
36
# File 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb', line 34

def group
  @match.captures[0]
end

#startObject



30
31
32
# File 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb', line 30

def start
  @match.begin(0)
end