Sha256: b401ffb63cfba51361f7f4e6a9c7e7d6ca0eca692c7306a22ec4bc2cc9e8003b

Contents?: true

Size: 664 Bytes

Versions: 1

Compression:

Stored size: 664 Bytes

Contents

# frozen_string_literal: true

module Vernacular
  # Represents a modification to Ruby source that should be injected into the
  # require process that modifies the source via a regex pattern.
  class RegexModifier
    attr_reader :pattern, :replacement, :block

    def initialize(pattern, replacement = nil, &block)
      @pattern = pattern
      @replacement = replacement
      @block = block
    end

    def modify(source)
      if replacement
        source.gsub(pattern, replacement)
      else
        source.gsub(pattern, &block)
      end
    end

    def components
      [pattern, replacement] + (block ? block.source_location : [])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vernacular-1.0.0 lib/vernacular/regex_modifier.rb