Class: DeepL::Requests::Translate

Inherits:
Base
  • Object
show all
Defined in:
lib/deepl/requests/translate.rb

Constant Summary collapse

OPTIONS_CONVERSIONS =
{
  split_sentences: { true => '1', false => '0' },
  preserve_formatting: { true => '1', false => '0' }
}.freeze

Constants inherited from Base

Base::API_VERSION

Instance Attribute Summary collapse

Attributes inherited from Base

#api, #options, #response

Instance Method Summary collapse

Constructor Details

#initialize(api, text, source_lang, target_lang, options = {}) ⇒ Translate

Returns a new instance of Translate.



11
12
13
14
15
16
17
18
# File 'lib/deepl/requests/translate.rb', line 11

def initialize(api, text, source_lang, target_lang, options = {})
  super(api, options)
  @text = text
  @source_lang = source_lang
  @target_lang = target_lang

  tweak_parameters!
end

Instance Attribute Details

#source_langObject (readonly)

Returns the value of attribute source_lang.



9
10
11
# File 'lib/deepl/requests/translate.rb', line 9

def source_lang
  @source_lang
end

#target_langObject (readonly)

Returns the value of attribute target_lang.



9
10
11
# File 'lib/deepl/requests/translate.rb', line 9

def target_lang
  @target_lang
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/deepl/requests/translate.rb', line 9

def text
  @text
end

Instance Method Details

#requestObject



20
21
22
23
# File 'lib/deepl/requests/translate.rb', line 20

def request
  payload = { text: text, source_lang: source_lang, target_lang: target_lang }
  build_texts(*post(payload))
end