Sha256: 0e05868e83741a556684b8de224ac56d7910fa5d68eec5d8328767a305b21f14

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

# Copyright 2024 DeepL SE (https://www.deepl.com)
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE file.
# frozen_string_literal: true

module DeepL
  module Resources
    class DocumentTranslationStatus < Base
      attr_reader :document_id, :status, :seconds_remaining, :billed_characters, :error_message

      def initialize(response, *args)
        super(*args)

        @document_id = response['document_id']
        @status = response['status']
        @seconds_remaining = response['seconds_remaining']
        @billed_characters = response['billed_characters']
        @error_message = response['error_message']
      end

      def to_s
        "DocumentTranslationStatus: ID: #{document_id} - Status: #{status} " \
          "- Error message: #{error_message}"
      end

      ##
      # Checks if the translation finished successfully
      #
      # @return [true] if so

      def successful?
        status == 'done'
      end

      ##
      # Checks if there was an error during translation
      #
      # @return [true] if so

      def error?
        status == 'error'
      end

      ##
      # Checks if the translation process terminated. Note that this could be due to an error as
      # well, but means no further waiting is necessary.
      #
      # @return [true] if so
      def finished?
        successful? || error?
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deepl-rb-3.1.0 lib/deepl/resources/document_translation_status.rb
deepl-rb-3.0.2 lib/deepl/resources/document_translation_status.rb
deepl-rb-3.0.1 lib/deepl/resources/document_translation_status.rb
deepl-rb-3.0.0 lib/deepl/resources/document_translation_status.rb