Class: Smartdict::Translator::Base

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

Instance Method Summary collapse

Constructor Details

#initialize(translator = nil) ⇒ Base

Just to make the interface compatible



5
6
# File 'lib/smartdict/translator/base.rb', line 5

def initialize(translator = nil)
end

Instance Method Details

#call(word, opts) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/smartdict/translator/base.rb', line 8

def call(word, opts)
  validate_opts!(opts)
  driver = Smartdict::Core::DriverManager.find(opts[:driver])

  translation_model = Models::Translation.find(word, opts[:from_lang], opts[:to_lang], opts[:driver])
  unless translation_model
    translation = driver.translate(word, opts[:from_lang], opts[:to_lang])
    translation_model = Models::Translation.create_from_struct(translation)
  end
  log_query(translation_model) if opts[:log]
  translation_model.to_struct
end