Sha256: eb4023b118d95e1dacc629ca06fd3900de975fad4efd0a7b7beeafdec9ab7176

Contents?: true

Size: 1023 Bytes

Versions: 3

Compression:

Stored size: 1023 Bytes

Contents

require "travelog/version"

module Travelog
  class Diff
    attr_reader :append, :delete

    def initialize
      @delete = {}
      @append = {}
    end

    ADD_LINE = /^\+\s*([\w-]+)\s\(([\d\.]+)\)/
    DEL_LINE = /^-\s*([\w-]+)\s\(([\d\.]+)\)/
    def <<(line)
      case line.strip
      when ADD_LINE
        append_set($1, $2)
      when DEL_LINE
        delete_set($1, $2)
      end
    end

    def report
      puts "***** CHANGED GEM'S *****"
      (append.keys & delete.keys).each do |k|
        puts "#{k} #{append[k]}(was #{delete[k]})"
      end

      puts
      puts "***** INSTALLED GEM'S *****"
      (append.keys - delete.keys).each do |k|
        puts "#{k} #{append[k]}"
      end

      puts
      puts "***** UNINSTALLED GEM'S *****"
      (delete.keys - append.keys).each do |k|
        puts "#{k} #{delete[k]}"
      end
    end

    private
    def append_set(name, version)
      append[name] = version
    end

    def delete_set(name, version)
      delete[name] = version
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
travelog-0.1.5 lib/travelog.rb
travelog-0.1.4 lib/travelog.rb
travelog-0.1.3 lib/travelog.rb