class DeepL::Requests::Translate
Constants
- ARRAY_CONVERSION
- BOOLEAN_CONVERSION
- OPTIONS_CONVERSIONS
Attributes
source_lang[R]
target_lang[R]
text[R]
Public Class Methods
new(api, text, source_lang, target_lang, options = {})
click to toggle source
Calls superclass method
DeepL::Requests::Base::new
# File lib/deepl/requests/translate.rb, line 17 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
Public Instance Methods
request()
click to toggle source
# File lib/deepl/requests/translate.rb, line 26 def request payload = { text: text, source_lang: source_lang, target_lang: target_lang } build_texts(*post(payload)) end
Private Instance Methods
build_texts(request, response)
click to toggle source
# File lib/deepl/requests/translate.rb, line 41 def build_texts(request, response) data = JSON.parse(response.body) texts = data['translations'].map do |translation| Resources::Text.new(translation['text'], translation['detected_source_language'], request, response) end texts.size == 1 ? texts.first : texts end
path()
click to toggle source
# File lib/deepl/requests/translate.rb, line 52 def path 'translate' end
tweak_parameters!()
click to toggle source
# File lib/deepl/requests/translate.rb, line 33 def tweak_parameters! OPTIONS_CONVERSIONS.each do |param, converter| next unless option?(param) && converter[option(param)] set_option(param, converter[option(param)]) end end