Class: DeepL::Requests::Translate
- Defined in:
- lib/deepl/requests/translate.rb
Constant Summary collapse
- STRING_TO_BOOLEAN_MAP =
{ '1' => true, '0' => false }.freeze
- BOOLEAN_TO_STRING_MAP =
{ true => '1', false => '0' }.freeze
- STRING_TO_BOOLEAN_CONVERSION =
->(value) { STRING_TO_BOOLEAN_MAP[value] }
- BOOLEAN_TO_STRING_CONVERSION =
->(value) { BOOLEAN_TO_STRING_MAP[value] }
- STRING_TO_ARRAY_CONVERSION =
lambda { |value| if value.nil? nil else (value.is_a?(Array) ? value : value.split(',')) end }.freeze
- OPTIONS_CONVERSIONS =
{ split_sentences: BOOLEAN_TO_STRING_CONVERSION, preserve_formatting: STRING_TO_BOOLEAN_CONVERSION, outline_detection: STRING_TO_BOOLEAN_CONVERSION, splitting_tags: STRING_TO_ARRAY_CONVERSION, non_splitting_tags: STRING_TO_ARRAY_CONVERSION, ignore_tags: STRING_TO_ARRAY_CONVERSION }.freeze
Instance Attribute Summary collapse
-
#ignore_tags ⇒ Object
readonly
Returns the value of attribute ignore_tags.
-
#non_splitting_tags ⇒ Object
readonly
Returns the value of attribute non_splitting_tags.
-
#source_lang ⇒ Object
readonly
Returns the value of attribute source_lang.
-
#splitting_tags ⇒ Object
readonly
Returns the value of attribute splitting_tags.
-
#target_lang ⇒ Object
readonly
Returns the value of attribute target_lang.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Attributes inherited from Base
Instance Method Summary collapse
- #details ⇒ Object
-
#initialize(api, text, source_lang, target_lang, options = {}) ⇒ Translate
constructor
A new instance of Translate.
- #request ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(api, text, source_lang, target_lang, options = {}) ⇒ Translate
Returns a new instance of Translate.
32 33 34 35 36 37 38 39 |
# File 'lib/deepl/requests/translate.rb', line 32 def initialize(api, text, source_lang, target_lang, = {}) super(api, ) @text = text @source_lang = source_lang @target_lang = target_lang tweak_parameters! end |
Instance Attribute Details
#ignore_tags ⇒ Object (readonly)
Returns the value of attribute ignore_tags.
29 30 31 |
# File 'lib/deepl/requests/translate.rb', line 29 def @ignore_tags end |
#non_splitting_tags ⇒ Object (readonly)
Returns the value of attribute non_splitting_tags.
29 30 31 |
# File 'lib/deepl/requests/translate.rb', line 29 def @non_splitting_tags end |
#source_lang ⇒ Object (readonly)
Returns the value of attribute source_lang.
29 30 31 |
# File 'lib/deepl/requests/translate.rb', line 29 def source_lang @source_lang end |
#splitting_tags ⇒ Object (readonly)
Returns the value of attribute splitting_tags.
29 30 31 |
# File 'lib/deepl/requests/translate.rb', line 29 def @splitting_tags end |
#target_lang ⇒ Object (readonly)
Returns the value of attribute target_lang.
29 30 31 |
# File 'lib/deepl/requests/translate.rb', line 29 def target_lang @target_lang end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
29 30 31 |
# File 'lib/deepl/requests/translate.rb', line 29 def text @text end |
Instance Method Details
#details ⇒ Object
47 48 49 50 |
# File 'lib/deepl/requests/translate.rb', line 47 def details "HTTP Headers: #{headers}\nPayload #{{ text: text, source_lang: source_lang, target_lang: target_lang }}" end |
#request ⇒ Object
41 42 43 44 45 |
# File 'lib/deepl/requests/translate.rb', line 41 def request text_arrayified = text.is_a?(Array) ? text : [text] payload = { text: text_arrayified, source_lang: source_lang, target_lang: target_lang } build_texts(*execute_request_with_retries(post_request(payload))) end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/deepl/requests/translate.rb', line 52 def to_s "POST #{uri.request_uri}" end |