Module: DeepL::Utils::TermValidator
Constant Summary collapse
- INVALID_CHARACTERS =
C0 and C1 control characters plus the Unicode line and paragraph separators.
/[\u0000-\u001F\u0080-\u009F ]/
Instance Method Summary collapse
-
#validate!(term) ⇒ String
Strips surrounding whitespace from a single glossary or spoken term, then checks it before it is serialized into a request.
Instance Method Details
#validate!(term) ⇒ String
Strips surrounding whitespace from a single glossary or spoken term, then checks it before it is serialized into a request.
22 23 24 25 26 27 28 29 30 |
# File 'lib/deepl/utils/term_validator.rb', line 22 def validate!(term) term = term.to_s.strip raise Exceptions::ValidationError, 'Term must not be empty' if term.empty? if INVALID_CHARACTERS.match?(term) raise Exceptions::ValidationError, "Term #{term.inspect} contains an invalid character" end term end |