Sha256: 9a94f1526309e4b5eae1b050bdac6003225df4f575de3ae7aa637bc1a2aab3a7

Contents?: true

Size: 759 Bytes

Versions: 2

Compression:

Stored size: 759 Bytes

Contents

module SSMD::Processors
  class Processor
    attr_reader :match, :options

    def initialize(options = {})
      @options = options
    end

    def matches?(input)
      @match = regex.match input

      !match.nil?
    end

    def substitute(input)
      join_parts match.pre_match, result, match.post_match if match
    end

    def strip_ssmd(input)
      join_parts match.pre_match, text, match.post_match if match
    end

    def text
      match.captures.first
    end

    def result
      raise "subclass responsibility"
    end

    def regex
      raise "subclass responsibility"
    end

    def warnings
      @warnings ||= []
    end

    private

    def join_parts(prefix, text, suffix)
      [prefix, text, suffix].join
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ssmd-0.7.6 lib/ssmd/processors/processor.rb
ssmd-0.7.5 lib/ssmd/processors/processor.rb