Class: Translatomatic::Translation::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/translatomatic/translation/result.rb

Overview

Data object describing a text translation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original, result, provider, options = {}) ⇒ Result

Returns a new instance of Result.



18
19
20
21
22
23
24
25
# File 'lib/translatomatic/translation/result.rb', line 18

def initialize(original, result, provider, options = {})
  raise 'original required' unless original.present?
  raise 'result required' unless result.present?
  @original = build_text(original)
  @result = build_text(result)
  @provider = provider
  @from_database = options[:from_database]
end

Instance Attribute Details

#from_databaseboolean (readonly)

Returns True if this translation came from the database.

Returns:

  • (boolean)

    True if this translation came from the database



16
17
18
# File 'lib/translatomatic/translation/result.rb', line 16

def from_database
  @from_database
end

#originalTranslatomatic::Text (readonly)

Returns original string.

Returns:



6
7
8
# File 'lib/translatomatic/translation/result.rb', line 6

def original
  @original
end

#providerSymbol (readonly)

Returns The name of the provider. Can be nil for translations that have been reconstituted from substrings.

Returns:

  • (Symbol)

    The name of the provider. Can be nil for translations that have been reconstituted from substrings.



13
14
15
# File 'lib/translatomatic/translation/result.rb', line 13

def provider
  @provider
end

#resultTranslatomatic::Text (readonly)

Returns translated string.

Returns:



9
10
11
# File 'lib/translatomatic/translation/result.rb', line 9

def result
  @result
end

Instance Method Details

#descriptionString

Returns A description of this translation.

Returns:

  • (String)

    A description of this translation



33
34
35
36
37
# File 'lib/translatomatic/translation/result.rb', line 33

def description
  format('%<original>s (%<from_locale>s) -> %<result>s (%<to_locale>s)',
         original: original.to_s, result: result.to_s,
         from_locale: original.locale, to_locale: result.locale)
end

#to_sString

Returns The translated string.

Returns:

  • (String)

    The translated string



28
29
30
# File 'lib/translatomatic/translation/result.rb', line 28

def to_s
  result.to_s
end