<commit_before>require 'time'

module SrtShifter
	class Subtitle
		
		def initialize(options)
			@opts = options
		end

		def shift

			start_time = Time.now

			output_file = File.open(@opts[:output], 'w')

			lines = IO.readlines(@opts[:input])

			lines.each do |line|

				time_match = line.force_encoding("iso-8859-1").scan(/(\d{2}:\d{2}:\d{2},\d{3}) --\> (\d{2}:\d{2}:\d{2},\d{3})/)
				
				if $1.nil? && $2.nil?
					output_file.write(line)
				else
					new_start_time = convert_time $1 
      				new_end_time = convert_time $2 
      				new_line = "#{new_start_time} --> #{new_end_time}\n"

      				output_file.write(new_line)
				end
			end

			end_time = Time.now

			puts "\nFile created with success!"
			puts "Elapsed time: #{end_time-start_time} seconds."
		end

		def convert_time time

			if @opts[:operation] == "SUB" and @opts[:time] > 0
				@opts[:time] = -@opts[:time]
			end

			current_time = Time.parse(time)
			new_time = Time.at(current_time.to_f + @opts[:time])
			"#{new_time.strftime('%H:%M:%S')},#{sprintf("%.3d",new_time.usec/1000)}"
		end<commit_msg>a little refactor in shift method<commit_after>require 'time'

module SrtShifter
	class Subtitle
		
		def initialize(options)
			@opts = options
		end

		def shift

			start_time = Time.now

			output_file = File.open(@opts[:output], 'w')

			lines = IO.readlines(@opts[:input])

			lines.each do |line|

				time_line = line.force_encoding("iso-8859-1")
				time_match = time_line.scan(/(\d{2}:\d{2}:\d{2},\d{3}) --\> (\d{2}:\d{2}:\d{2},\d{3})/)
				
				if $1.nil? && $2.nil?
					output_file.write(line)
				else
					new_start_time = convert_time $1 
      				new_end_time = convert_time $2 
      				new_line = "#{new_start_time} --> #{new_end_time}\n"

      				output_file.write(new_line)
				end
			end

			end_time = Time.now

			puts "\nFile created with success!"
			puts "Elapsed time: #{end_time-start_time} seconds."
		end

		def convert_time time

			if @opts[:operation] == "SUB" and @opts[:time] > 0
				@opts[:time] = -@opts[:time]
			end

			current_time = Time.parse(time)
			new_time = Time.at(current_time.to_f + @opts[:time])
			"#{new_time.strftime('%H:%M:%S')},#{sprintf("%.3d",new_time.usec/1000)}"
		end
{'fraction_non_alphanumeric': 0.1752252252252252, 'fraction_numerical': 0.02072072072072072, 'mean_word_length': 3.0162748643761303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3798152', 'n_tokens_mistral': 1040, 'n_tokens_neox': 856, 'n_words': 156}