Sha256: a2947c69738af3d2b4e676ef26e9ae7d50c70cbbfb8b532c91f1123a41431293

Contents?: true

Size: 1.52 KB

Versions: 9

Compression:

Stored size: 1.52 KB

Contents

module AbstractImporter
  module Reporters
    class BaseReporter
      attr_reader :io

      def initialize(io)
        @io = io
      end



      def start_all(importer)
        io.puts "Importing #{importer.describe_source} to #{importer.describe_destination}\n"
      end

      def finish_all(importer, ms)
        io.puts "\n\nFinished in #{distance_of_time(ms)}"
      end

      def finish_setup(importer, ms)
      end

      def finish_teardown(importer, ms)
      end

      def start_collection(collection)
        io.puts "\n#{("="*80)}\nImporting #{collection.name}\n#{("="*80)}\n"
      end

      def finish_collection(collection, summary)
      end



      def record_created(record)
      end

      def record_failed(record, hash)
      end

      def record_skipped(hash)
      end

      def batch_inserted(size)
      end



      def count_notice(message)
      end

      def count_error(message)
      end



    protected

      def distance_of_time(milliseconds)
        milliseconds = milliseconds.to_i
        seconds = milliseconds / 1000
        milliseconds %= 1000
        minutes = seconds / 60
        seconds %= 60
        hours = minutes / 60
        minutes %= 60
        days = hours / 24
        hours %= 24

        time = []
        time << "#{days} days" unless days.zero?
        time << "#{hours} hours" unless hours.zero?
        time << "#{minutes} minutes" unless minutes.zero?
        time << "#{seconds}.#{milliseconds.to_s.rjust(3, "0")} seconds"
        time.join(", ")
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
abstract_importer-1.9.0 lib/abstract_importer/reporters/base_reporter.rb
abstract_importer-1.8.0 lib/abstract_importer/reporters/base_reporter.rb
abstract_importer-1.7.0 lib/abstract_importer/reporters/base_reporter.rb
abstract_importer-1.6.0 lib/abstract_importer/reporters/base_reporter.rb
abstract_importer-1.5.6 lib/abstract_importer/reporters/base_reporter.rb
abstract_importer-1.5.5 lib/abstract_importer/reporters/base_reporter.rb
abstract_importer-1.5.4 lib/abstract_importer/reporters/base_reporter.rb
abstract_importer-1.5.3 lib/abstract_importer/reporters/base_reporter.rb
abstract_importer-1.5.2 lib/abstract_importer/reporters/base_reporter.rb