Class: DeepL::Requests::Translate

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

Constant Summary collapse

BOOLEAN_CONVERSION =
{ true => '1', false => '0' }.freeze
ARRAY_CONVERSION =
->(value) { value.is_a?(Array) ? value.join(', ') : value }.freeze
OPTIONS_CONVERSIONS =
{
  split_sentences: BOOLEAN_CONVERSION,
  preserve_formatting: BOOLEAN_CONVERSION,
  non_splitting_tags: ARRAY_CONVERSION,
  ignore_tags: ARRAY_CONVERSION
}.freeze

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.



15
16
17
18
19
20
21
22
# File 'lib/deepl/requests/translate.rb', line 15

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

#ignore_tagsObject (readonly)

Returns the value of attribute ignore_tags.



13
14
15
# File 'lib/deepl/requests/translate.rb', line 13

def ignore_tags
  @ignore_tags
end

#non_splitting_tagsObject (readonly)

Returns the value of attribute non_splitting_tags.



13
14
15
# File 'lib/deepl/requests/translate.rb', line 13

def non_splitting_tags
  @non_splitting_tags
end

#source_langObject (readonly)

Returns the value of attribute source_lang.



13
14
15
# File 'lib/deepl/requests/translate.rb', line 13

def source_lang
  @source_lang
end

#target_langObject (readonly)

Returns the value of attribute target_lang.



13
14
15
# File 'lib/deepl/requests/translate.rb', line 13

def target_lang
  @target_lang
end

#textObject (readonly)

Returns the value of attribute text.



13
14
15
# File 'lib/deepl/requests/translate.rb', line 13

def text
  @text
end

Instance Method Details

#requestObject



24
25
26
27
# File 'lib/deepl/requests/translate.rb', line 24

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