Class: SrtTranslate
- Inherits:
-
Object
- Object
- SrtTranslate
- Defined in:
- lib/deepl_srt/srt_translate.rb
Overview
Class to translate subtitles
Instance Method Summary collapse
-
#initialize(api_key, target_lang, input_path, result_path) ⇒ SrtTranslate
constructor
A new instance of SrtTranslate.
- #parse(from_line) ⇒ Object
Constructor Details
#initialize(api_key, target_lang, input_path, result_path) ⇒ SrtTranslate
Returns a new instance of SrtTranslate.
10 11 12 13 14 15 16 |
# File 'lib/deepl_srt/srt_translate.rb', line 10 def initialize(api_key, target_lang, input_path, result_path) @file = SRT::File.parse(File.new(input_path)) @deepl_request = DeeplRequest.new(api_key) @target_lang = target_lang FileUtils.touch(result_path) unless File.exist?(result_path) @result_path = result_path end |
Instance Method Details
#parse(from_line) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/deepl_srt/srt_translate.rb', line 18 def parse(from_line) @new_content = '' @file.lines.drop(from_line.to_i).each_with_index do |line, index| @new_content << parse_part(line, index + from_line.to_i) end @new_content end |