File: group_builder.rb

package info (click to toggle)
ruby-cucumber-expressions 8.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 248 kB
  • sloc: ruby: 1,594; sh: 15; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 919 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'cucumber/cucumber_expressions/group'

module Cucumber
  module CucumberExpressions
    class GroupBuilder
      attr_accessor :source

      def initialize
        @group_builders = []
        @capturing = true
      end

      def add(group_builder)
        @group_builders.push(group_builder)
      end

      def build(match, group_indices)
        group_index = group_indices.next
        children = @group_builders.map {|gb| gb.build(match, group_indices)}
        Group.new(match[group_index], match.offset(group_index)[0], match.offset(group_index)[1], children)
      end

      def set_non_capturing!
        @capturing = false
      end

      def capturing?
        @capturing
      end

      def move_children_to(group_builder)
        @group_builders.each do |child|
          group_builder.add(child)
        end
      end

      def children
        @group_builders
      end
    end
  end
end