class Subtitle class << self def handle_time(time) reset time = time.to_s @hour = time[-6..-5] if time.length >= 6 @min = time[-4..-3] if time.length >= 4 @sec = time[-2..-1] if time.length >= 2 start_time = "#{hour}:#{min}:#{sec}" end_time = "#{hour}:#{min}:#{sec.to_i+10}" return start_time, end_time end def handle_content(ctn) ctn.gsub(%r{(^\s+)|(\s+$)}, "") end def hex2rgb(hexadecimal) deleted_signs = %r{#|0x} hex = hex2s(hexadecimal) if hex.match(deleted_signs) hex.gsub!(deleted_signs, "") end hex_arr = hex.split("") rgb = [] r = hex2decimal hex_arr[0..1].join g = hex2decimal hex_arr[2..3].join b = hex2decimal hex_arr[4..5].join [r, g, b].map(&:to_i) #if hex.match(%r{#}) # hex.gsub(%r{#}, "") #end # #rgb = {} #%w(r g b).inject(hex) do |rest, i| # rest, rgb[i] = rest.divmod 256 # rest #end end def rgb2hex(r, g, b) hex = [r, g, b].map do |e| format_value(decimal2hex(e)) end "#" + hex.join end private def format_value(value) if value.length == 1 "0#{value}" else value end end def decimal2hex(decimal) hex = [] rest = decimal begin rest, remainder= rest.divmod 16 hex << translate(remainder) end until rest == 0 hex.join end def hex2s(hex) if hex.is_a? Fixnum hex.to_s else hex end end def hex2decimal(hexadecimal) hex = hex2s(hexadecimal) if hex.is_a? Fixnum hex = hex.to_s end if hex.match(%r{#}) hex.gsub(%r{#}, "") end translate = {} hex_arr = hex.to_s.split("") len = hex_arr.length hex_arr.each_with_index do |e, index| place = len.to_i - index - 1 translate[place] = translate(e) end decimal = 0 translate.each do |place, e| decimal += e.to_i*16**place end decimal end def power(base_num, index_num) eval [base_num]*index_num.join("*") end def translate(value) result = value dict.each do |hex, decimal| if decimal == value result = hex.to_s break end if hex.to_s == value result = decimal break end end result end def dict {a: 10, b: 11, c: 12, d: 13, e: 14, f: 15} end def reset instance_variables.each do |iv| instance_variable_set iv, nil end end def hour @hour ||= "00" end def min @min ||= "00" end def sec @sec ||= "00" end end end