Class: Cucumber::RbSupport::RbGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/rb_support/rb_group.rb

Overview

A Group encapsulates data from a regexp match. A Group instance has to attributes:

  • The value of the group

  • The start index from the matched string where the group value starts

See rb_group_spec.rb for examples

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(val, start) ⇒ RbGroup

Returns a new instance of RbGroup.



27
28
29
# File 'lib/cucumber/rb_support/rb_group.rb', line 27

def initialize(val, start)
  @val, @start = val, start
end

Instance Attribute Details

#startObject (readonly)

Returns the value of attribute start.



12
13
14
# File 'lib/cucumber/rb_support/rb_group.rb', line 12

def start
  @start
end

#valObject (readonly)

Returns the value of attribute val.



12
13
14
# File 'lib/cucumber/rb_support/rb_group.rb', line 12

def val
  @val
end

Class Method Details

.groups_from(regexp, step_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cucumber/rb_support/rb_group.rb', line 14

def self.groups_from(regexp, step_name)
  match = regexp.match(step_name)
  if match
    n = 0
    match.captures.map do |val|
      n += 1
      new(val, match.offset(n)[0])
    end
  else
    nil
  end
end