Sha256: b442a760dcc0633f240117a8d22993a8f67d2a61d194d21479c4b259f838977c

Contents?: true

Size: 841 Bytes

Versions: 2

Compression:

Stored size: 841 Bytes

Contents

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

    def diff(*args, &block)
      build_diff_collection do
        adapter.diff(*args, &block)
      end
    end

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

    private

    attr_reader :string, :type

    def build_diff_collection(&block)
      collection.reset(&block).dup
    end

    def collection
      @collection ||= Collection.new(string)
    end

    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.6 lib/sub_diff/builder.rb
sub_diff-1.0.5 lib/sub_diff/builder.rb