Class: Rsubtitle::SMI
Constant Summary collapse
- SMI_RE =
%r( ^<sync\sstart=(\d+)> <p[^>]+> (?:\r?\n)? ( \ (?=\r?\n) | (?<=\n).+?(?=\r?\n) ) )xim
Instance Attribute Summary
Attributes inherited from Subtitle
Class Method Summary collapse
Instance Method Summary collapse
- #[](idx) ⇒ Object
-
#initialize(file) ⇒ SMI
constructor
A new instance of SMI.
- #size ⇒ Object
Methods inherited from Subtitle
Constructor Details
#initialize(file) ⇒ SMI
Returns a new instance of SMI.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rsubtitle/smi.rb', line 31 def initialize(file) @body = open(file).read lines = @body.scan(SMI_RE) @entries = [] lines.each_with_index do |d, idx| next if d[1] == " " start = d[0].to_i duration = (lines[idx+1].nil?) ? 0 : (lines[idx+1][0].to_i - start) sub = d[1] sub.gsub!(/<br\s*\/?>/i, "\n") # br -> \n sub.gsub!(/<[^>]+?>/i, "") # strip tags sub.strip! e = Entry.new e.start = start e.body = sub e.duration = duration @entries << e end end |
Class Method Details
Instance Method Details
#[](idx) ⇒ Object
62 63 64 |
# File 'lib/rsubtitle/smi.rb', line 62 def [](idx) @entries[idx] end |
#size ⇒ Object
58 59 60 |
# File 'lib/rsubtitle/smi.rb', line 58 def size @entries.size end |