Class: Lit::CloudTranslation::Providers::Base
- Inherits:
-
Object
- Object
- Lit::CloudTranslation::Providers::Base
- Defined in:
- lib/lit/cloud_translation/providers/base.rb
Overview
Abstract base class for cloud translation providers, providing a skeleton for the provider’s functionality (mainly the #translate method) as well as a configuration management mechanism.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
- .configure {|config| ... } ⇒ Object
-
.translate(text:, from: nil, to:, **opts) ⇒ Object
Using the provider object’s singleton instance, translates a given text from a given language to a different one.
Instance Method Summary collapse
-
#initialize(config) ⇒ Base
constructor
A new instance of Base.
-
#translate(text:, from: nil, to:, **opts) ⇒ Object
Translates a given text from a given language to a different one.
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 |
# File 'lib/lit/cloud_translation/providers/base.rb', line 10 def initialize(config) default_config.each do |key, value| config[key] ||= value end @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/lit/cloud_translation/providers/base.rb', line 8 def config @config end |
Class Method Details
.configure {|config| ... } ⇒ Object
51 52 53 |
# File 'lib/lit/cloud_translation/providers/base.rb', line 51 def configure yield config if block_given? end |
.translate(text:, from: nil, to:, **opts) ⇒ Object
Using the provider object’s singleton instance, translates a given text from a given language to a different one.
47 48 49 |
# File 'lib/lit/cloud_translation/providers/base.rb', line 47 def translate(text:, from: nil, to:, **opts) instance.translate(text: text, from: from, to: to, **opts) end |
Instance Method Details
#translate(text:, from: nil, to:, **opts) ⇒ Object
Translates a given text from a given language to a different one.
23 24 25 |
# File 'lib/lit/cloud_translation/providers/base.rb', line 23 def translate(text:, from: nil, to:, **opts) # rubocop:disable Lint/UnusedMethodArgument, Metrics/LineLength raise NotImplementedError end |