deepl-rb 3.0.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ed15fdabc7d3b893b4590bda599106140c9c06c7d4d67cc6ff2a679a05ba301
4
- data.tar.gz: fee679c9456728c0679ebdf66ea501d7924eb49e9e1e480520a50a6c7cfed3d9
3
+ metadata.gz: 47bf797967929a4b7775e21ce7021cdc1871283b3358cbb36d13a8f6f6b5ac6b
4
+ data.tar.gz: df4399cc6c552fb5c03b79b0566d2370101b58246bfd5e0b05d27c83e994ae6c
5
5
  SHA512:
6
- metadata.gz: eefd241705fc379dd6de1574a63f83380cb445a6d883c7d2db6da3827691b79845b06f37227c0ea0285738066ba1850782e0462ec9fab9a02816205ab416ba35
7
- data.tar.gz: c6f0789c07f2f23c27a9ee979812b0d76bde2edb308cd2e6c422f826a089f561cdb6c80317dfecb27ed94d9f2ee6c6340135548ea3866bb21084896da28ceb3d
6
+ metadata.gz: 4639c87e107dfa0a13b1bace938e9a3580fb15bb1e2f280267527e3d5d0c9b8913752b841bd095039f1e4f7d15b13813075131c0767216855bf5e7d28a4b81a1
7
+ data.tar.gz: 19743f57e84c550e5fe35b1d6c39f853df1d0d1d357eb8c0f061a0202831af8a557651f34f50dcad10928b45638a3a09b9ab64652fdadab6d6ad62ec3f2a1242
data/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [3.2.0]
8
+ ### Added
9
+ * Added `rephrase` functionality to get a new version of submitted text with various possible styles or tones applied
10
+ * Added `DeepL::Constants` namespace and associated constant values for options possibilities
11
+
12
+ ## [3.1.0]
13
+ ### Added
14
+ * Added `model_type` option to `translate()` to use models with higher
15
+ translation quality (available for some language pairs), or better latency.
16
+ Options are `'quality_optimized'`, `'latency_optimized'`, and `'prefer_quality_optimized'`
17
+ * Added the `model_type_used` field to the `translate()` response, that
18
+ indicates the translation model used when the `model_type` option is
19
+ specified.
20
+
7
21
 
8
22
  ## [3.0.2] - 2024-10-02
9
23
  ### Added
@@ -40,7 +54,8 @@ The change in major version is only due to the change in maintainership, there i
40
54
  ### Fixed
41
55
  * Make RequestEntityTooLarge error message more clear
42
56
 
43
-
57
+ [3.2.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.1.0...3.2.0
58
+ [3.1.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.2...v3.1.0
44
59
  [3.0.2]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.1...v3.0.2
45
60
  [3.0.1]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.0...v3.0.1
46
61
  [3.0.0]: https://github.com/DeepLcom/deepl-rb/compare/v2.5.3...v3.0.0
data/README.md CHANGED
@@ -137,6 +137,23 @@ puts translation.text
137
137
  # => "¡Eso es picante!"
138
138
  ```
139
139
 
140
+ To specify a type of translation model to use, you can use the `model_type` option:
141
+
142
+ ```rb
143
+ translation = DeepL.translate 'That is hot!', 'EN', 'DE',
144
+ model_type: 'quality_optimized'
145
+ ```
146
+
147
+ This would use next-gen translation models for the translation. The available values are
148
+
149
+ - `'quality_optimized'`: use a translation model that maximizes translation quality, at the
150
+ cost of response time. This option may be unavailable for some language pairs.
151
+ - `'prefer_quality_optimized'`: use the highest-quality translation model for the given
152
+ language pair.
153
+ - `'latency_optimized'`: use a translation model that minimizes response time, at the cost
154
+ of translation quality.
155
+
156
+
140
157
  The following parameters will be automatically converted:
141
158
 
142
159
  | Parameter | Conversion
@@ -151,6 +168,37 @@ The following parameters will be automatically converted:
151
168
  | `glossary_id` | No conversion applied
152
169
  | `context` | No conversion applied
153
170
 
171
+ ### Rephrase Text
172
+
173
+ To rephrase or improve text, including changing the writing style or tone of the text, use the `rephrase` method:
174
+
175
+ ```rb
176
+ rephrased_text = DeepL.rephrase 'you will acquire new rephrased text', 'EN'
177
+
178
+ puts rephrased_text.class
179
+ # => DeepL::Resources::Text
180
+ puts rephrased_text.text
181
+ # => 'You get new rephrased text.'
182
+ ```
183
+
184
+ As with translate, the text input can be a single string or an array of strings.
185
+
186
+ You can use the additional arguments to specify the writing style or tone you want for the rephrased text:
187
+
188
+ ```rb
189
+ rephrased_text = DeepL.rephrase 'you will acquire new rephrased text', 'EN', 'casual'
190
+
191
+ puts rephrased_text.text
192
+ # => 'You'll get new, rephrased text.'
193
+ ```
194
+
195
+ ```rb
196
+ rephrased_text = DeepL.rephrase 'you will acquire new rephrased text', 'EN', nil, 'friendly'
197
+
198
+ puts rephrased_text.text
199
+ # => 'You'll get to enjoy new, rephrased text!'
200
+ ```
201
+
154
202
  ### Glossaries
155
203
 
156
204
  To create a glossary, use the `glossaries.create` method. The glossary `entries` argument should be an array of text pairs. Each pair includes the source and the target translations.
@@ -372,6 +420,30 @@ end
372
420
 
373
421
  This information is passed along when the library makes calls to the DeepL API. Both name and version are required. Please note that setting the `User-Agent` header via `deepl.configure` will override this setting, if you need to use this, please manually identify your Application in the `User-Agent` header.
374
422
 
423
+ ## Options Constants
424
+
425
+ The available values for various possible options are provided under the `DeepL::Constants` namespace. The currently available options are
426
+
427
+ `TagHandling`
428
+ `SplitSentences`
429
+ `ModelType`
430
+ `Formality`
431
+ `WritingStyle`
432
+ `Tone`
433
+
434
+ To view all the possible options for a given constant, call `options`:
435
+
436
+ ```rb
437
+ all_available_tones = DeepL::Constants::Tones.options
438
+ ```
439
+
440
+ To check if a given string is a possible option for a given constant, call `valid?`:
441
+
442
+ ```rb
443
+ DeepL::Constants::Tones.valid?('friendly') # true
444
+ DeepL::Constants::Tones.valid?('rude') # false
445
+ ```
446
+
375
447
  ## Integrations
376
448
 
377
449
  ### Ruby on Rails
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.2
1
+ 3.2.0
data/deepl-rb.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: deepl-rb 3.0.2 ruby lib
5
+ # stub: deepl-rb 3.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "deepl-rb".freeze
9
- s.version = "3.0.2"
9
+ s.version = "3.2.0".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.metadata = { "bug_tracker_uri" => "https://github.com/DeepLcom/deepl-rb/issues", "changelog_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/CHANGELOG.md", "documentation_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/README.md", "homepage_uri" => "https://github.com/DeepLcom/deepl-rb" } if s.respond_to? :metadata=
13
13
  s.require_paths = ["lib".freeze]
14
14
  s.authors = ["DeepL SE".freeze]
15
- s.date = "2024-10-02"
15
+ s.date = "2025-01-15"
16
16
  s.description = "Official Ruby library for the DeepL language translation API (v2). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
17
17
  s.email = "open-source@deepl.com".freeze
18
18
  s.extra_rdoc_files = [
@@ -39,6 +39,13 @@ Gem::Specification.new do |s|
39
39
  "lib/deepl.rb",
40
40
  "lib/deepl/api.rb",
41
41
  "lib/deepl/configuration.rb",
42
+ "lib/deepl/constants/base_constant.rb",
43
+ "lib/deepl/constants/formality.rb",
44
+ "lib/deepl/constants/model_type.rb",
45
+ "lib/deepl/constants/split_sentences.rb",
46
+ "lib/deepl/constants/tag_handling.rb",
47
+ "lib/deepl/constants/tone.rb",
48
+ "lib/deepl/constants/writing_style.rb",
42
49
  "lib/deepl/document_api.rb",
43
50
  "lib/deepl/exceptions/authorization_failed.rb",
44
51
  "lib/deepl/exceptions/bad_request.rb",
@@ -63,6 +70,7 @@ Gem::Specification.new do |s|
63
70
  "lib/deepl/requests/glossary/language_pairs.rb",
64
71
  "lib/deepl/requests/glossary/list.rb",
65
72
  "lib/deepl/requests/languages.rb",
73
+ "lib/deepl/requests/rephrase.rb",
66
74
  "lib/deepl/requests/translate.rb",
67
75
  "lib/deepl/requests/usage.rb",
68
76
  "lib/deepl/resources/base.rb",
@@ -80,6 +88,7 @@ Gem::Specification.new do |s|
80
88
  "spec/api/api_spec.rb",
81
89
  "spec/api/configuration_spec.rb",
82
90
  "spec/api/deepl_spec.rb",
91
+ "spec/constants/constants_spec.rb",
83
92
  "spec/fixtures/vcr_cassettes/deepl_document.yml",
84
93
  "spec/fixtures/vcr_cassettes/deepl_document_download.yml",
85
94
  "spec/fixtures/vcr_cassettes/deepl_glossaries.yml",
@@ -88,6 +97,7 @@ Gem::Specification.new do |s|
88
97
  "spec/fixtures/vcr_cassettes/deepl_usage.yml",
89
98
  "spec/fixtures/vcr_cassettes/glossaries.yml",
90
99
  "spec/fixtures/vcr_cassettes/languages.yml",
100
+ "spec/fixtures/vcr_cassettes/rephrase_texts.yml",
91
101
  "spec/fixtures/vcr_cassettes/translate_texts.yml",
92
102
  "spec/fixtures/vcr_cassettes/usage.yml",
93
103
  "spec/integration_tests/document_api_spec.rb",
@@ -99,6 +109,7 @@ Gem::Specification.new do |s|
99
109
  "spec/requests/glossary/language_pairs_spec.rb",
100
110
  "spec/requests/glossary/list_spec.rb",
101
111
  "spec/requests/languages_spec.rb",
112
+ "spec/requests/rephrase_spec.rb",
102
113
  "spec/requests/translate_spec.rb",
103
114
  "spec/requests/usage_spec.rb",
104
115
  "spec/resources/glossary_spec.rb",
@@ -110,12 +121,12 @@ Gem::Specification.new do |s|
110
121
  ]
111
122
  s.homepage = "https://github.com/DeepLcom/deepl-rb".freeze
112
123
  s.licenses = ["MIT".freeze]
113
- s.rubygems_version = "3.4.6".freeze
124
+ s.rubygems_version = "3.5.3".freeze
114
125
  s.summary = "Official Ruby library for the DeepL language translation API.".freeze
115
126
 
116
127
  s.specification_version = 4
117
128
 
118
- s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
119
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
129
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0".freeze])
130
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0".freeze])
120
131
  end
121
132
 
@@ -0,0 +1,18 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class BaseConstant
9
+ def self.options
10
+ constants.map { |const| const_get(const) }
11
+ end
12
+
13
+ def self.valid?(value)
14
+ options.include?(value)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class Formality < BaseConstant
9
+ DEFAULT = 'default'
10
+ MORE = 'more'
11
+ LESS = 'less'
12
+ PREFER_MORE = 'prefer_more'
13
+ PREFER_LESS = 'prefer_less'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class ModelType < BaseConstant
9
+ QUALITY_OPTIMIZED = 'quality_optimized'
10
+ PREFER_QUALITY_OPTIMIZED = 'prefer_quality_optimized'
11
+ LATENCY_OPTIMIZED = 'latency_optimized'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class SplitSentences < BaseConstant
9
+ NO_SPLITTING = '0'
10
+ SPLIT_ON_PUNCTUATION_AND_NEWLINES = '1'
11
+ SPLIT_ON_PUNCTUATION_ONLY = 'nonewlines'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class TagHandling < BaseConstant
9
+ XML = 'xml'
10
+ HTML = 'html'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class Tone < BaseConstant
9
+ DEFAULT = 'default'
10
+ ENTHUSIASTIC = 'enthusiastic'
11
+ FRIENDLY = 'friendly'
12
+ CONFIDENT = 'confident'
13
+ DIPLOMATIC = 'diplomatic'
14
+ PREFER_ENTHUSIASTIC = 'prefer_enthusiastic'
15
+ PREFER_FRIENDLY = 'prefer_friendly'
16
+ PREFER_CONFIDENT = 'prefer_confident'
17
+ PREFER_DIPLOMATIC = 'prefer_diplomatic'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class WritingStyle < BaseConstant
9
+ DEFAULT = 'default'
10
+ SIMPLE = 'simple'
11
+ BUSINESS = 'business'
12
+ ACADEMIC = 'academic'
13
+ CASUAL = 'casual'
14
+ PREFER_SIMPLE = 'prefer_simple'
15
+ PREFER_BUSINESS = 'prefer_business'
16
+ PREFER_ACADEMIC = 'prefer_academic'
17
+ PREFER_CASUAL = 'prefer_casual'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Requests
8
+ class Rephrase < Base
9
+ attr_reader :text, :target_lang, :writing_style, :tone
10
+
11
+ def initialize(api, text, target_lang, writing_style = nil, tone = nil, options = {})
12
+ super(api, options)
13
+ @text = text
14
+ @target_lang = target_lang
15
+ @writing_style = writing_style
16
+ @tone = tone
17
+ end
18
+
19
+ def request
20
+ text_arrayified = text.is_a?(Array) ? text : [text]
21
+ payload = { text: text_arrayified, target_lang: target_lang }
22
+ payload[:writing_style] = writing_style unless writing_style.nil?
23
+ payload[:tone] = tone unless tone.nil?
24
+ build_texts(*execute_request_with_retries(post_request(payload)))
25
+ end
26
+
27
+ def details
28
+ "HTTP Headers: #{headers}\nPayload #{{ text: text, target_lang: target_lang,
29
+ writing_style: writing_style, tone: tone }}"
30
+ end
31
+
32
+ def to_s
33
+ "POST #{uri.request_uri}"
34
+ end
35
+
36
+ private
37
+
38
+ def build_texts(request, response)
39
+ data = JSON.parse(response.body)
40
+
41
+ texts = data['improvements'].map do |improvement|
42
+ Resources::Text.new(improvement['text'], improvement['detected_source_language'], nil,
43
+ request, response)
44
+ end
45
+
46
+ texts.size == 1 ? texts.first : texts
47
+ end
48
+
49
+ def path
50
+ 'write/rephrase'
51
+ end
52
+ end
53
+ end
54
+ end
@@ -27,7 +27,7 @@ module DeepL
27
27
  }.freeze
28
28
 
29
29
  attr_reader :text, :source_lang, :target_lang, :ignore_tags, :splitting_tags,
30
- :non_splitting_tags
30
+ :non_splitting_tags, :model_type
31
31
 
32
32
  def initialize(api, text, source_lang, target_lang, options = {})
33
33
  super(api, options)
@@ -68,7 +68,7 @@ module DeepL
68
68
 
69
69
  texts = data['translations'].map do |translation|
70
70
  Resources::Text.new(translation['text'], translation['detected_source_language'],
71
- request, response)
71
+ translation['model_type_used'], request, response)
72
72
  end
73
73
 
74
74
  texts.size == 1 ? texts.first : texts
@@ -6,13 +6,14 @@
6
6
  module DeepL
7
7
  module Resources
8
8
  class Text < Base
9
- attr_reader :text, :detected_source_language
9
+ attr_reader :text, :detected_source_language, :model_type_used
10
10
 
11
- def initialize(text, detected_source_language, *args)
11
+ def initialize(text, detected_source_language, model_type_used, *args)
12
12
  super(*args)
13
13
 
14
14
  @text = text
15
15
  @detected_source_language = detected_source_language
16
+ @model_type_used = model_type_used
16
17
  end
17
18
 
18
19
  def to_s
data/lib/deepl.rb CHANGED
@@ -34,6 +34,7 @@ require 'deepl/requests/glossary/list'
34
34
  require 'deepl/requests/languages'
35
35
  require 'deepl/requests/translate'
36
36
  require 'deepl/requests/usage'
37
+ require 'deepl/requests/rephrase'
37
38
 
38
39
  # -- Responses and resources
39
40
  require 'deepl/resources/base'
@@ -49,6 +50,15 @@ require 'deepl/resources/usage'
49
50
  require 'deepl/utils/exception_builder'
50
51
  require 'deepl/utils/backoff_timer'
51
52
 
53
+ # -- Constants
54
+ require 'deepl/constants/base_constant'
55
+ require 'deepl/constants/formality'
56
+ require 'deepl/constants/model_type'
57
+ require 'deepl/constants/split_sentences'
58
+ require 'deepl/constants/tag_handling'
59
+ require 'deepl/constants/tone'
60
+ require 'deepl/constants/writing_style'
61
+
52
62
  # -- HTTP Utils
53
63
  require 'http_client_options'
54
64
 
@@ -0,0 +1,158 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ require 'spec_helper'
7
+
8
+ describe 'DeepL::Constants' do
9
+ describe DeepL::Constants::Tone do
10
+ subject(:tone) { described_class }
11
+
12
+ it 'includes all expected tone values' do # rubocop:disable RSpec/ExampleLength
13
+ expect(tone.options).to contain_exactly(
14
+ 'confident',
15
+ 'default',
16
+ 'diplomatic',
17
+ 'enthusiastic',
18
+ 'friendly',
19
+ 'prefer_confident',
20
+ 'prefer_diplomatic',
21
+ 'prefer_enthusiastic',
22
+ 'prefer_friendly'
23
+ )
24
+ end
25
+
26
+ it 'validates correct tone values' do
27
+ expect(tone.valid?('enthusiastic')).to be true
28
+ expect(tone.valid?('friendly')).to be true
29
+ expect(tone.valid?('confident')).to be true
30
+ expect(tone.valid?('diplomatic')).to be true
31
+ expect(tone.valid?('default')).to be true
32
+ end
33
+
34
+ it 'invalidates incorrect tone values' do
35
+ expect(tone.valid?('angry')).to be false
36
+ expect(tone.valid?('')).to be false
37
+ expect(tone.valid?(nil)).to be false
38
+ end
39
+ end
40
+
41
+ describe DeepL::Constants::WritingStyle do
42
+ subject(:writing_style) { described_class }
43
+
44
+ it 'includes all expected writing style values' do # rubocop:disable RSpec/ExampleLength
45
+ expect(writing_style.options).to contain_exactly(
46
+ 'default',
47
+ 'simple',
48
+ 'business',
49
+ 'academic',
50
+ 'casual',
51
+ 'prefer_academic',
52
+ 'prefer_business',
53
+ 'prefer_casual',
54
+ 'prefer_simple'
55
+ )
56
+ end
57
+
58
+ it 'validates correct writing style values' do
59
+ expect(writing_style.valid?('simple')).to be true
60
+ expect(writing_style.valid?('business')).to be true
61
+ expect(writing_style.valid?('academic')).to be true
62
+ expect(writing_style.valid?('casual')).to be true
63
+ expect(writing_style.valid?('default')).to be true
64
+ end
65
+
66
+ it 'invalidates incorrect writing style values' do
67
+ expect(writing_style.valid?('wordy')).to be false
68
+ expect(writing_style.valid?('')).to be false
69
+ expect(writing_style.valid?(nil)).to be false
70
+ end
71
+ end
72
+
73
+ describe DeepL::Constants::TagHandling do
74
+ subject(:tag_handling) { described_class }
75
+
76
+ it 'includes all expected tag handling values' do
77
+ expect(tag_handling.options).to contain_exactly('xml', 'html')
78
+ end
79
+
80
+ it 'validates correct tag handling values' do
81
+ expect(tag_handling.valid?('xml')).to be true
82
+ expect(tag_handling.valid?('html')).to be true
83
+ end
84
+
85
+ it 'invalidates incorrect tag handling values' do
86
+ expect(tag_handling.valid?('json')).to be false
87
+ expect(tag_handling.valid?('')).to be false
88
+ expect(tag_handling.valid?(nil)).to be false
89
+ end
90
+ end
91
+
92
+ describe DeepL::Constants::SplitSentences do
93
+ subject(:split_sentences) { described_class }
94
+
95
+ it 'includes all expected split sentences values' do
96
+ expect(split_sentences.options).to contain_exactly('0', '1', 'nonewlines')
97
+ end
98
+
99
+ it 'validates correct split sentences values' do
100
+ expect(split_sentences.valid?('0')).to be true
101
+ expect(split_sentences.valid?('1')).to be true
102
+ expect(split_sentences.valid?('nonewlines')).to be true
103
+ end
104
+
105
+ it 'invalidates incorrect split sentences values' do
106
+ expect(split_sentences.valid?('2')).to be false
107
+ expect(split_sentences.valid?('')).to be false
108
+ expect(split_sentences.valid?(nil)).to be false
109
+ end
110
+ end
111
+
112
+ describe DeepL::Constants::ModelType do
113
+ subject(:model_type) { described_class }
114
+
115
+ it 'includes all expected model type values' do
116
+ expect(model_type.options).to contain_exactly(
117
+ 'quality_optimized',
118
+ 'prefer_quality_optimized',
119
+ 'latency_optimized'
120
+ )
121
+ end
122
+
123
+ it 'validates correct model type values' do
124
+ expect(model_type.valid?('quality_optimized')).to be true
125
+ expect(model_type.valid?('prefer_quality_optimized')).to be true
126
+ expect(model_type.valid?('latency_optimized')).to be true
127
+ end
128
+
129
+ it 'invalidates incorrect model type values' do
130
+ expect(model_type.valid?('speed_optimized')).to be false
131
+ expect(model_type.valid?('')).to be false
132
+ expect(model_type.valid?(nil)).to be false
133
+ end
134
+ end
135
+
136
+ describe DeepL::Constants::Formality do
137
+ subject(:formality) { described_class }
138
+
139
+ it 'includes all expected formality values' do
140
+ expect(formality.options).to contain_exactly('default', 'more', 'less', 'prefer_more',
141
+ 'prefer_less')
142
+ end
143
+
144
+ it 'validates correct formality values' do
145
+ expect(formality.valid?('default')).to be true
146
+ expect(formality.valid?('more')).to be true
147
+ expect(formality.valid?('less')).to be true
148
+ expect(formality.valid?('prefer_more')).to be true
149
+ expect(formality.valid?('prefer_less')).to be true
150
+ end
151
+
152
+ it 'invalidates incorrect formality values' do
153
+ expect(formality.valid?('neutral')).to be false
154
+ expect(formality.valid?('')).to be false
155
+ expect(formality.valid?(nil)).to be false
156
+ end
157
+ end
158
+ end