Sha256: 49cdfec294454d98d021ac434ece8335c8d74dd203096aaa6f1b4350cf717531

Contents?: true

Size: 622 Bytes

Versions: 1

Compression:

Stored size: 622 Bytes

Contents

module SubDiff
  class Collection < SimpleDelegator
    extend Forwardable
    include Enumerable

    def_delegators :diffs, :each, :size

    attr_reader :string, :diffs

    def initialize(string)
      @string = string
      @diffs = []
      super(string)
    end

    def changed?
      diffs.any?(&:changed?)
    end

    def clear
      diffs.clear
      __setobj__('')
      self
    end

    def push(diff)
      unless diff.empty?
        diffs << diff
        __setobj__(diffs.join)
      end
    end

    def reset
      clear
      __setobj__(string)
      yield if block_given?
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sub_diff-1.1.0 lib/sub_diff/collection.rb