Class: DeepL::Resources::TranslationMemoryJobResult

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

Overview

The outcome of a translation memory import or export job.

Constant Summary collapse

STATUS_AWAITING_INPUT =
'awaiting_input'
STATUS_PROCESSING =
'processing'
STATUS_COMPLETED =
'completed'
STATUS_DOWNLOADED =
'downloaded'
STATUS_FAILED =
'failed'
STATUS_EXPIRED =
'expired'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ TranslationMemoryJobResult

Returns a new instance of TranslationMemoryJobResult.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/deepl/resources/translation_memory_job.rb', line 22

def initialize(result)
   = result['status_metadata'] || {}
  error = result['error'] || {}

  @status = result['status']
  @required_action = ['required_action']
  @download_url = result['download_url']
  @expires_at = Utils::TimeParser.parse_optional_time(result['expires_at'])
  @error_message = error['message']
  @translation_memory_id = result['translation_memory_id']
  @skipped_segment_count = result['skipped_segment_count']
end

Instance Attribute Details

#download_urlObject (readonly)

Returns the value of attribute download_url.



19
20
21
# File 'lib/deepl/resources/translation_memory_job.rb', line 19

def download_url
  @download_url
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



19
20
21
# File 'lib/deepl/resources/translation_memory_job.rb', line 19

def error_message
  @error_message
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



19
20
21
# File 'lib/deepl/resources/translation_memory_job.rb', line 19

def expires_at
  @expires_at
end

#required_actionObject (readonly)

Returns the value of attribute required_action.



19
20
21
# File 'lib/deepl/resources/translation_memory_job.rb', line 19

def required_action
  @required_action
end

#skipped_segment_countObject (readonly)

Returns the value of attribute skipped_segment_count.



19
20
21
# File 'lib/deepl/resources/translation_memory_job.rb', line 19

def skipped_segment_count
  @skipped_segment_count
end

#statusObject (readonly)

Returns the value of attribute status.



19
20
21
# File 'lib/deepl/resources/translation_memory_job.rb', line 19

def status
  @status
end

#translation_memory_idObject (readonly)

Returns the value of attribute translation_memory_id.



19
20
21
# File 'lib/deepl/resources/translation_memory_job.rb', line 19

def translation_memory_id
  @translation_memory_id
end

Instance Method Details

#awaiting_input?true

Checks if the job is still waiting for the TMX file to be uploaded. Note that the API detects an upload asynchronously, so a job keeps reporting this status for a while after its file has been uploaded.

Returns:

  • (true)

    if so



52
53
54
# File 'lib/deepl/resources/translation_memory_job.rb', line 52

def awaiting_input?
  status == STATUS_AWAITING_INPUT
end

#error?true

Checks if there was an error during the job, including it having expired.

Returns:

  • (true)

    if so



61
62
63
# File 'lib/deepl/resources/translation_memory_job.rb', line 61

def error?
  [STATUS_FAILED, STATUS_EXPIRED].include?(status)
end

#finished?true

Checks if the job terminated. Note that this could be due to an error as well, but means no further waiting is necessary.

Returns:

  • (true)

    if so



41
42
43
# File 'lib/deepl/resources/translation_memory_job.rb', line 41

def finished?
  [STATUS_COMPLETED, STATUS_DOWNLOADED, STATUS_FAILED, STATUS_EXPIRED].include?(status)
end

#to_sObject



65
66
67
# File 'lib/deepl/resources/translation_memory_job.rb', line 65

def to_s
  "TranslationMemoryJobResult: Status: #{status} - Error message: #{error_message}"
end