Sha256: ef83b2c1997a096daad2f635ea0fc4b718d8b17641a0a258c965365c0809f240

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

module Lhm
  module Printer

    class Output
      def write(message)
        print message
      end
    end

    class Base

      def initialize
        @output = Output.new
      end
    end

    class Percentage < Base

      def initialize
        super
        @max_length = 0
      end

      def notify(lowest, highest)
        return if !highest || highest == 0
        message = "%.2f%% (#{lowest}/#{highest}) complete" % (lowest.to_f / highest * 100.0)
        write(message)
      end

      def end
        write("100% complete")
        @output.write "\n"
      end

      private
      def write(message)
        if (extra = @max_length - message.length) < 0
          @max_length = message.length
          extra = 0
        end

        @output.write "\r#{message}" + (" " * extra)
      end
    end

    class Dot < Base
      def notify(lowest = nil, highest = nil)
        @output.write "."
      end

      def end
        @output.write "\n"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lhm-2.1.0 lib/lhm/printer.rb