Sha256: 52b06a488fb7450b8945bee03fe61474f22e47db97c2f66bf2299890d6a07038

Contents?: true

Size: 716 Bytes

Versions: 2

Compression:

Stored size: 716 Bytes

Contents

module SubDiff
  class Builder
    def initialize(string, type)
      @string = string
      @type = type
    end

    def diff(*args, &block)
      @collection = Collection.new(string)
      adapter.diff(*args, &block)
      collection
    end

    def push(*args)
      if args.compact.any?
        diff = Diff.new(*args)
        collection.push(diff)
      end
    end
    alias_method :<<, :push

    private

    attr_reader :collection, :string, :type

    def adapter
      adapter_class.new(differ)
    end

    def adapter_class
      Module.nesting.last.const_get(adapter_name)
    end

    def adapter_name
      type.to_s.capitalize
    end

    def differ
      Differ.new(self, type)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sub_diff-1.0.4 lib/sub_diff/builder.rb
sub_diff-1.0.3 lib/sub_diff/builder.rb