Class: DeepL::Resources::TranslationMemorySegments

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

Overview

One page of the segments of a translation memory. Pagination is cursor-based: pass next_page_cursor as the page_cursor option of the next request until it is nil.

Instance Attribute Summary collapse

Attributes inherited from Base

#request, #response

Instance Method Summary collapse

Constructor Details

#initialize(segments_response, *args) ⇒ TranslationMemorySegments

Returns a new instance of TranslationMemorySegments.



53
54
55
56
57
58
59
60
61
62
# File 'lib/deepl/resources/translation_memory_segments.rb', line 53

def initialize(segments_response, *args)
  super(*args)
  @segments = (segments_response['segments'] || []).map do |segment|
    TranslationMemorySegment.new(segment)
  end
  # Note that this is the number of segments stored in the translation memory, it is not
  # reduced by a text filter.
  @segment_count = segments_response['segment_count'] || 0
  @next_page_cursor = segments_response['next_page_cursor']
end

Instance Attribute Details

#next_page_cursorObject (readonly)

Returns the value of attribute next_page_cursor.



51
52
53
# File 'lib/deepl/resources/translation_memory_segments.rb', line 51

def next_page_cursor
  @next_page_cursor
end

#segment_countObject (readonly)

Returns the value of attribute segment_count.



51
52
53
# File 'lib/deepl/resources/translation_memory_segments.rb', line 51

def segment_count
  @segment_count
end

#segmentsObject (readonly)

Returns the value of attribute segments.



51
52
53
# File 'lib/deepl/resources/translation_memory_segments.rb', line 51

def segments
  @segments
end

Instance Method Details

#next_page?true

Checks whether another page of segments can be requested.

Returns:

  • (true)

    if so



69
70
71
# File 'lib/deepl/resources/translation_memory_segments.rb', line 69

def next_page?
  !next_page_cursor.nil?
end

#to_sObject



73
74
75
# File 'lib/deepl/resources/translation_memory_segments.rb', line 73

def to_s
  "#{segments.size} of #{segment_count} segment(s)"
end