Class: Ehbrs::Runner::Google::Translate
- Inherits:
-
EacRubyUtils::Console::DocoptRunner
- Object
- EacRubyUtils::Console::DocoptRunner
- Ehbrs::Runner::Google::Translate
- Includes:
- EacCli::DefaultRunner
- Defined in:
- lib/ehbrs/runner/google/translate.rb
Instance Method Summary collapse
- #default_output_file ⇒ Object
- #output_file ⇒ Object
- #output_to_stdout? ⇒ Boolean
- #run ⇒ Object
- #session_uncached ⇒ Object
- #source_file ⇒ Object
- #start_banner ⇒ Object
- #translated_content_uncached ⇒ Object
- #validate ⇒ Object
- #validate_output_content ⇒ Object
- #validate_output_file ⇒ Object
- #validate_source_file ⇒ Object
Instance Method Details
#default_output_file ⇒ Object
49 50 51 52 53 54 |
# File 'lib/ehbrs/runner/google/translate.rb', line 49 def default_output_file ::File.join( ::File.dirname(source_file), ::File.basename(source_file, '.*') + '_translated.html' ) end |
#output_file ⇒ Object
45 46 47 |
# File 'lib/ehbrs/runner/google/translate.rb', line 45 def output_file .fetch('--output-file') || default_output_file end |
#output_to_stdout? ⇒ Boolean
86 87 88 |
# File 'lib/ehbrs/runner/google/translate.rb', line 86 def output_to_stdout? output_file == '-' end |
#run ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ehbrs/runner/google/translate.rb', line 21 def run validate if output_to_stdout? out(translated_content) else ::File.write(output_file, translated_content) end success 'Concluído' end |
#session_uncached ⇒ Object
56 57 58 |
# File 'lib/ehbrs/runner/google/translate.rb', line 56 def session_uncached ::Ehbrs::Google::Translate::Session.new end |
#source_file ⇒ Object
41 42 43 |
# File 'lib/ehbrs/runner/google/translate.rb', line 41 def source_file .fetch('<source-file>') end |
#start_banner ⇒ Object
32 33 34 35 |
# File 'lib/ehbrs/runner/google/translate.rb', line 32 def infov 'Source file', source_file infov 'Target file', output_file end |
#translated_content_uncached ⇒ Object
37 38 39 |
# File 'lib/ehbrs/runner/google/translate.rb', line 37 def translated_content_uncached session.translate(source_file) end |
#validate ⇒ Object
60 61 62 63 64 |
# File 'lib/ehbrs/runner/google/translate.rb', line 60 def validate validate_source_file validate_output_file validate_output_content end |
#validate_output_content ⇒ Object
80 81 82 83 84 |
# File 'lib/ehbrs/runner/google/translate.rb', line 80 def validate_output_content return if translated_content.present? fatal_error 'Output content is empty' end |
#validate_output_file ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/ehbrs/runner/google/translate.rb', line 72 def validate_output_file return if output_to_stdout? return unless ::File.exist?(output_file) return if .fetch('--overwrite') fatal_error "Output file \"#{output_file}\" already exists" end |
#validate_source_file ⇒ Object
66 67 68 69 70 |
# File 'lib/ehbrs/runner/google/translate.rb', line 66 def validate_source_file return if ::File.exist?(source_file) fatal_error "Source file \"#{source_file}\" does not exist" end |