Class: STRTime
Constant Summary collapse
- REGEX =
'([[:digit:]]+):([[:digit:]]+):([[:digit:]]+)[,\.]([[:digit:]]{3})'
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #+(bump) ⇒ Object
-
#initialize(value) ⇒ STRTime
constructor
A new instance of STRTime.
- #to_srt ⇒ Object
Constructor Details
#initialize(value) ⇒ STRTime
Returns a new instance of STRTime.
16 17 18 |
# File 'lib/storyboard/time.rb', line 16 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/storyboard/time.rb', line 3 def value @value end |
Class Method Details
.parse(str, skip_encode = false) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/storyboard/time.rb', line 6 def parse(str, skip_encode=false) matcher = skip_encode ? Regexp.new(REGEX) : Storyboard.encode_regexp(REGEX) hh,mm,ss,ms = str.scan(matcher).flatten.map{|i| Float(i.force_encoding("ASCII-8bit").delete("\000")) } value = ((((hh*60)+mm)*60)+ss) + ms/1000 self.new(value) end |
Instance Method Details
#+(bump) ⇒ Object
20 21 22 |
# File 'lib/storyboard/time.rb', line 20 def +(bump) STRTime.new(@value + bump) end |
#to_srt ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/storyboard/time.rb', line 24 def to_srt ss = @value.floor ms = ((@value - ss)*1000).to_i mm = ss / 60 ss = ss - mm * 60 hh = mm / 60 mm = mm - hh * 60 "%02i:%02i:%02i.%03i" % [hh, mm, ss, ms] end |