Sha256: ccd0064118d33d486fef0e61975e038f317b28716af7a5ea76250421d62b10c4

Contents?: true

Size: 744 Bytes

Versions: 2

Compression:

Stored size: 744 Bytes

Contents

module SubDiff
  class Builder
    attr_reader :string, :diff_method

    def initialize(string, diff_method)
      @string = string
      @diff_method = diff_method
    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

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

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

    def adapter
      @adapter ||= Adapter.new(differ)
    end

    def differ
      @differ ||= Differ.new(self)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sub_diff-1.1.0 lib/sub_diff/builder.rb
sub_diff-1.0.7 lib/sub_diff/builder.rb