class Translatomatic::Translation::Result

Data object describing a text translation

Attributes

from_database[R]

@return [boolean] True if this translation came from the database

original[R]

@return [Translatomatic::Text] original string

provider[R]

@return [Symbol] The name of the provider. Can be nil for translations

that have been reconstituted from substrings.
result[R]

@return [Translatomatic::Text] translated string

Public Class Methods

new(original, result, provider, options = {}) click to toggle source
# 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

Public Instance Methods

description() click to toggle source

@return [String] A description of this translation

# 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_s() click to toggle source

@return [String] The translated string

# File lib/translatomatic/translation/result.rb, line 28
def to_s
  result.to_s
end

Private Instance Methods

build_text(string) click to toggle source
# File lib/translatomatic/translation/result.rb, line 41
def build_text(string)
  if string.is_a?(Translatomatic::Text)
    string
  else
    Translatomatic::Text.new(string, Locale.default)
  end
end