Module: Acts::Timecode::InstanceMethods
- Defined in:
- lib/acts_as_timecode.rb
Instance Method Summary collapse
Instance Method Details
#timecode ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/acts_as_timecode.rb', line 27 def timecode hours = send(timecode_column).to_i/(60*60).to_i rem = send(timecode_column).to_i - hours * (60*60) minutes = rem/(60).to_i rem = rem - minutes * (60) seconds = rem @timecode = "#{hours.to_s.rjust(2,'0')}:#{minutes.to_s.rjust(2,'0')}:#{seconds.to_s.rjust(2,'0')}" end |
#timecode=(value) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/acts_as_timecode.rb', line 36 def timecode=(value) matches = value.split(':') matches.map!{|s| s.to_i} case matches.length #HH:MM:SS:FF when 4 write_attribute(timecode_column, ((matches[0]*60*60) + (matches[1] * 60) + matches[2] + matches[3]/fps).round) #HH:MM:SS when 3 write_attribute(timecode_column, (matches[0]*60*60) + (matches[1] * 60) + matches[2]) #MM:SS when 2 write_attribute(timecode_column, matches[0] * (60) + matches[1]) #SS else write_attribute(timecode_column, value) end end |