Sha256: b7a8e75f313c55d5ac73a5ec7ce3fa308ca2fece85847a15aadca408ccbef0cd

Contents?: true

Size: 1.32 KB

Versions: 24

Compression:

Stored size: 1.32 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
      def initialize
        @max_length = 0
      end

      def notify(lowest, highest)
        return if !highest || highest == 0

        # The argument lowest represents the next_to_insert row id, and highest represents the 
        # maximum id upto which chunker has to copy the data. 
        # If all the rows are inserted upto highest, then lowest passed here from chunker was 
        # highest + 1, which leads to the printer printing the progress > 100%.
        return if lowest >= highest
        
        message = "%.2f%% (#{lowest}/#{highest}) complete" % (lowest.to_f / highest * 100.0)
        write(message)
      end

      def end
        write('100% complete')
      end

      def exception(e)
        Lhm.logger.error("failed: #{e}")
      end

      private

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

        Lhm.logger.info(message)
      end
    end

    class Dot < Base
      def notify(*)
        @output.write '.'
      end

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

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
lhm-shopify-4.4.2 lib/lhm/printer.rb
lhm-shopify-4.4.1 lib/lhm/printer.rb
lhm-shopify-4.4.0 lib/lhm/printer.rb
lhm-shopify-4.3.0 lib/lhm/printer.rb
lhm-shopify-4.2.3 lib/lhm/printer.rb
lhm-shopify-4.2.2 lib/lhm/printer.rb
lhm-shopify-4.2.1 lib/lhm/printer.rb
lhm-shopify-4.2.0 lib/lhm/printer.rb
lhm-shopify-4.1.1 lib/lhm/printer.rb
lhm-shopify-4.1.0 lib/lhm/printer.rb
lhm-shopify-4.0.0 lib/lhm/printer.rb
lhm-teak-3.6.4 lib/lhm/printer.rb
lhm-teak-3.6.3 lib/lhm/printer.rb
lhm-teak-3.6.2 lib/lhm/printer.rb
lhm-teak-3.6.1 lib/lhm/printer.rb
lhm-teak-3.6.0 lib/lhm/printer.rb
lhm-shopify-3.5.5 lib/lhm/printer.rb
lhm-shopify-3.5.4 lib/lhm/printer.rb
lhm-shopify-3.5.3 lib/lhm/printer.rb
lhm-shopify-3.5.2 lib/lhm/printer.rb