Class: DeepL::Resources::DocumentHandle

Inherits:
Base
  • Object
show all
Defined in:
lib/deepl/resources/document_handle.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#request, #response

Instance Method Summary collapse

Constructor Details

#initialize(document_id, document_key, *args) ⇒ DocumentHandle

Returns a new instance of DocumentHandle.



11
12
13
14
15
16
# File 'lib/deepl/resources/document_handle.rb', line 11

def initialize(document_id, document_key, *args)
  super(*args)

  @document_id = document_id
  @document_key = document_key
end

Instance Attribute Details

#document_idObject (readonly)

Returns the value of attribute document_id.



9
10
11
# File 'lib/deepl/resources/document_handle.rb', line 9

def document_id
  @document_id
end

#document_keyObject (readonly)

Returns the value of attribute document_key.



9
10
11
# File 'lib/deepl/resources/document_handle.rb', line 9

def document_key
  @document_key
end

Instance Method Details

#to_sObject



18
19
20
# File 'lib/deepl/resources/document_handle.rb', line 18

def to_s
  "DocumentHandle: ID: #{document_id} - Key: #{document_key}"
end

#wait_until_document_translation_finishedDeepL::Resources::DocumentTranslationStatus

For this DocumentHandle, waits until the document translation is finished and returns the final status of the document.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/deepl/resources/document_handle.rb', line 29

def wait_until_document_translation_finished
  doc_status = nil
  max_tries = max_doc_status_queries
  num_tries = 0
  loop do
    num_tries += 1
    sleep(calculate_waiting_time(doc_status)) unless doc_status.nil?
    doc_status = DeepL.document.get_status(self)
    break if doc_status.finished? || num_tries > max_tries
  end
  doc_status
end