Class: Cucumber::CucumberExpressions::TreeRegexp

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp) ⇒ TreeRegexp

Returns a new instance of TreeRegexp.



11
12
13
14
# File 'lib/cucumber/cucumber_expressions/tree_regexp.rb', line 11

def initialize(regexp)
  @regexp = regexp.is_a?(Regexp) ? regexp : Regexp.new(regexp)
  @group_builder = create_group_builder(@regexp)
end

Instance Attribute Details

#group_builderObject (readonly)

Returns the value of attribute group_builder.



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

def group_builder
  @group_builder
end

#regexpObject (readonly)

Returns the value of attribute regexp.



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

def regexp
  @regexp
end

Instance Method Details

#match(s) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/cucumber/cucumber_expressions/tree_regexp.rb', line 16

def match(s)
  match = @regexp.match(s)
  return nil if match.nil?

  group_indices = (0..match.length).to_a.to_enum
  @group_builder.build(match, group_indices)
end