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
      45 46 47 48 49 50  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 45 def default_output_file ::File.join( ::File.dirname(source_file), "#{::File.basename(source_file, '.*')}_translated.html" ) end  | 
  
#output_file ⇒ Object
      41 42 43  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 41 def output_file parsed.output_file || default_output_file end  | 
  
#output_to_stdout? ⇒ Boolean
      82 83 84  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 82 def output_to_stdout? output_file == '-' end  | 
  
#run ⇒ Object
      19 20 21 22 23 24 25 26 27 28  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 19 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
      52 53 54  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 52 def session_uncached ::Ehbrs::Google::Translate::Session.new end  | 
  
#start_banner ⇒ Object
      30 31 32 33  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 30 def infov 'Source file', source_file infov 'Target file', output_file end  | 
  
#translated_content_uncached ⇒ Object
      35 36 37  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 35 def translated_content_uncached session.translate(source_file) end  | 
  
#validate ⇒ Object
      56 57 58 59 60  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 56 def validate validate_source_file validate_output_file validate_output_content end  | 
  
#validate_output_content ⇒ Object
      76 77 78 79 80  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 76 def validate_output_content return if translated_content.present? fatal_error 'Output content is empty' end  | 
  
#validate_output_file ⇒ Object
      68 69 70 71 72 73 74  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 68 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
      62 63 64 65 66  | 
    
      # File 'lib/ehbrs/tools/runner/google/translate.rb', line 62 def validate_source_file return if ::File.exist?(source_file) fatal_error "Source file \"#{source_file}\" does not exist" end  |