Class: Purizumu::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/purizumu/translator.rb

Overview

Resolves a translated attribute, generating and caching it on demand.

Instance Method Summary collapse

Constructor Details

#initialize(record:, attribute_name:, locale:) ⇒ Translator

Returns a new instance of Translator.



6
7
8
9
10
# File 'lib/purizumu/translator.rb', line 6

def initialize(record:, attribute_name:, locale:)
  @record = record
  @attribute_name = attribute_name.to_s
  @locale = locale.to_s
end

Instance Method Details

#callObject



12
13
14
15
16
17
# File 'lib/purizumu/translator.rb', line 12

def call
  return source_content if source_content.nil? || source_content == ''
  return source_content unless record.persisted?

  existing_translation&.content || create_translation!.content
end