Created
November 30, 2011 20:43
-
-
Save sshaw/1410732 to your computer and use it in GitHub Desktop.
Harris Timecode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HarrisTimecode | |
attr_accessor :hours, :minutes, :seconds, :frames, :encoded | |
def initialize(encoded) | |
raise ArgumentError, "Encoded duration invalid: #{encoded}" unless encoded.respond_to?(:to_i) | |
hex = "%08x" % encoded.to_i | |
@hours, @minutes, @seconds, @frames = [0,2,4,6].map { |n| hex[n, 2] } | |
@encoded = encoded | |
end | |
def to_s | |
"#{@hours}:#{@minutes}:#{@seconds}:#{@frames}" | |
end | |
end | |
puts HarrisTimecode.new(140562) # 00:02:25:12 | |
puts HarrisTimecode.new(4096) # 00:00:00:10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment