Sha256: 4d85258cdd7922dd1c54aaaea0451903df8352a49aed6a1e78fbc41f29b89f18

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

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

      def exception(e)
        write("failed: #{e}")
        @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(*)
        @output.write '.'
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lhm-shopify-3.4.0 lib/lhm/printer.rb
lhm-shopify-3.3.6 lib/lhm/printer.rb
lhm-shopify-3.3.5 lib/lhm/printer.rb