Class: Subtitle
- Inherits:
-
Object
- Object
- Subtitle
- Defined in:
- lib/subtitle.rb
Class Method Summary collapse
- .handle_content(ctn) ⇒ Object
- .handle_time(time) ⇒ Object
- .hex2rgb(hexadecimal) ⇒ Object
- .rgb2hex(r, g, b) ⇒ Object
Class Method Details
.handle_content(ctn) ⇒ Object
14 15 16 |
# File 'lib/subtitle.rb', line 14 def handle_content(ctn) ctn.gsub(%r{(^\s+)|(\s+$)}, "") end |
.handle_time(time) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/subtitle.rb', line 3 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 |
.hex2rgb(hexadecimal) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/subtitle.rb', line 18 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 |
.rgb2hex(r, g, b) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/subtitle.rb', line 45 def rgb2hex(r, g, b) hex = [r, g, b].map do |e| format_value(decimal2hex(e)) end "#" + hex.join end |