Sha256: 3664d082919b96b630dd6b9a36cf7c955e7d5ca08e7526a5be14859fd94db546

Contents?: true

Size: 925 Bytes

Versions: 2

Compression:

Stored size: 925 Bytes

Contents

module Ecoportal
  module API
    class V1
      class Job
        class Status
          attr_reader :id, :progress

          def initialize(id, complete, errored, progress)
            @id       = id
            @complete = complete
            @errored  = errored
            @progress = progress
          end

          def complete?(total = nil)
            return @complete if total.nil?

            progress >= total
          end

          def pending(total)
            return 1 unless total
            return 0 if total <= progress

            total - progress
          end

          def errored?
            @errored
          end

          def to_s
            msg = complete? ? "Completed" : "In progress"
            msg = "Errored" if errored?
            msg << " with #{progress} done."
            msg
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ecoportal-api-0.10.5 lib/ecoportal/api/v1/job/status.rb
ecoportal-api-0.10.4 lib/ecoportal/api/v1/job/status.rb