Sha256: 5c344c5e27ce8f5a9f283742a03622e5cb2850fdc1d244598da28c711199a394

Contents?: true

Size: 633 Bytes

Versions: 5

Compression:

Stored size: 633 Bytes

Contents

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

5 entries across 5 versions & 1 rubygems

Version Path
vernacular-0.1.2 lib/vernacular/regex_modifier.rb
vernacular-0.1.1 lib/vernacular/regex_modifier.rb
vernacular-0.1.0 lib/vernacular/regex_modifier.rb
vernacular-0.0.2 lib/vernacular/regex_modifier.rb
vernacular-0.0.1 lib/vernacular/regex_modifier.rb