Class: DeeplAPI::CLI
- Inherits:
-
Thor
- Object
- Thor
- DeeplAPI::CLI
- Defined in:
- lib/deepl_api/cli.rb
Overview
This class implements the ‘deepl` command line utility.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
9 10 11 12 |
# File 'lib/deepl_api/cli.rb', line 9 def self.exit_on_failure? # Exit in case of missing arguments etc. true end |
Instance Method Details
#languages ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/deepl_api/cli.rb', line 22 def languages deepl = instance source_langs = deepl.source_languages target_langs = deepl.target_languages puts("DeepL can translate from the following source languages:") source_langs.each { |language, name| puts(" #{language.ljust(5)} (#{name})") } puts puts("DeepL can translate to the following target languages:") target_langs.each { |language, name| puts(" #{language.ljust(5)} (#{name})") } end |
#translate ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/deepl_api/cli.rb', line 43 def translate formality = DeeplAPI::Formality::DEFAULT formality = DeeplAPI::Formality::LESS if ["formality-less"] formality = DeeplAPI::Formality::MORE if ["formality-more"] text = if ["input-file"] File.read(["input-file"]) else $stdin.read end result = instance.translate( source_language: ["source-language"], target_language: ["target-language"], preserve_formatting: ["preserve-formatting"], formality: formality, texts: [text] ) text = result.map { |entry| entry["text"] }.join if ["output-file"] File.write(["output-file"], text) else puts text end end |
#usage_information ⇒ Object
15 16 17 18 19 |
# File 'lib/deepl_api/cli.rb', line 15 def usage_information usage = instance.usage_information puts("Available characters per billing period: #{usage.character_limit}") puts("Characters already translated in the current billing period: #{usage.character_count}") end |