Sha256: 491c82c92ed356c3079c026ea76a46e6c35f8de3c442e29a44c64e249aa8aeb3

Contents?: true

Size: 503 Bytes

Versions: 6

Compression:

Stored size: 503 Bytes

Contents

module RegexpExamples
  class BackReferenceReplacer
    def substitute_backreferences(full_examples)
      full_examples.map do |full_example|
        while full_example.match(/__(\w+?)__/)
          full_example.sub!(/__(\w+?)__/, find_backref_for(full_example, $1))
        end
        full_example
      end
    end

    private
    def find_backref_for(full_example, group_id)
      full_example.all_subgroups.detect do |subgroup|
        subgroup.group_id == group_id
      end
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
regexp-examples-0.3.2 lib/regexp-examples/backreferences.rb
regexp-examples-0.3.1 lib/regexp-examples/backreferences.rb
regexp-examples-0.3.0 lib/regexp-examples/backreferences.rb
regexp-examples-0.2.4 lib/regexp-examples/backreferences.rb
regexp-examples-0.2.3 lib/regexp-examples/backreferences.rb
regexp-examples-0.2.2 lib/regexp-examples/backreferences.rb