Class: Smartdict::Translator
- Inherits:
-
Object
- Object
- Smartdict::Translator
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/smartdict/translator.rb
Defined Under Namespace
Classes: Base, DriverConfiguration, LanguageDetector
Instance Attribute Summary collapse
-
#default_opts ⇒ Object
readonly
Returns the value of attribute default_opts.
Instance Method Summary collapse
-
#initialize(default_opts = {}) ⇒ Translator
constructor
A new instance of Translator.
- #translate(word, opts = {}) ⇒ Object
Constructor Details
#initialize(default_opts = {}) ⇒ Translator
Returns a new instance of Translator.
11 12 13 14 15 |
# File 'lib/smartdict/translator.rb', line 11 def initialize(default_opts = {}) @default_opts = default_opts @middleware_classes = [Base, DriverConfiguration, LanguageDetector] @middleware = build_middleware end |
Instance Attribute Details
#default_opts ⇒ Object (readonly)
Returns the value of attribute default_opts.
9 10 11 |
# File 'lib/smartdict/translator.rb', line 9 def default_opts @default_opts end |
Instance Method Details
#translate(word, opts = {}) ⇒ Object
17 18 19 20 |
# File 'lib/smartdict/translator.rb', line 17 def translate(word, opts = {}) opts.reverse_merge!(default_opts) @middleware.last.call(word, opts) end |