Class: Ehbrs::Tools::Runner::Google::Translate
- Inherits:
-
Object
- Object
- Ehbrs::Tools::Runner::Google::Translate
- Defined in:
- lib/ehbrs/tools/runner/google/translate.rb
Instance Method Summary collapse
- #default_output_file ⇒ Object
- #output_file ⇒ Object
- #output_to_stdout? ⇒ Boolean
- #run ⇒ Object
- #session_uncached ⇒ 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
41 42 43 44 45 46 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 41 def default_output_file ::File.join( ::File.dirname(source_file), "#{::File.basename(source_file, '.*')}_translated.html" ) end |
#output_file ⇒ Object
37 38 39 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 37 def output_file parsed.output_file || default_output_file end |
#output_to_stdout? ⇒ Boolean
78 79 80 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 78 def output_to_stdout? output_file == '-' end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 15 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
48 49 50 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 48 def session_uncached ::Ehbrs::Tools::Google::Translate::Session.new end |
#start_banner ⇒ Object
26 27 28 29 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 26 def infov 'Source file', source_file infov 'Target file', output_file end |
#translated_content_uncached ⇒ Object
31 32 33 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 31 def translated_content_uncached session.translate(source_file) end |
#validate ⇒ Object
52 53 54 55 56 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 52 def validate validate_source_file validate_output_file validate_output_content end |
#validate_output_content ⇒ Object
72 73 74 75 76 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 72 def validate_output_content return if translated_content.present? fatal_error 'Output content is empty' end |
#validate_output_file ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 64 def validate_output_file return if output_to_stdout? return unless ::File.exist?(output_file) return if parsed.overwrite? fatal_error "Output file \"#{output_file}\" already exists" end |
#validate_source_file ⇒ Object
58 59 60 61 62 |
# File 'lib/ehbrs/tools/runner/google/translate.rb', line 58 def validate_source_file return if ::File.exist?(source_file) fatal_error "Source file \"#{source_file}\" does not exist" end |