create new instance of OggInfo use of charset is deprecated! please use utf-8 encoded strings and leave charset to nil")
# File lib/ogginfo.rb, line 39 def initialize(filename, charset = nil) if charset warn("use of charset is deprecated! please use utf-8 encoded tags") end @filename = filename @length = nil @bitrate = nil filesize = File.size(@filename) File.open(@filename, 'rb') do |file| begin info = read_headers(file) @samplerate = info[:samplerate] @nominal_bitrate = info[:nominal_bitrate] @channels = info[:channels] @tag = info[:tag] # filesize is used to calculate bitrate # but we don't want to include the headers @filesize = file.stat.size - file.pos rescue Ogg::StreamError => se raise(OggInfoError, se.message, se.backtrace) end end @original_tag = @tag.dup end
"block version" of ::new()
# File lib/ogginfo.rb, line 84 def self.open(*args) m = self.new(*args) ret = nil if block_given? begin ret = yield(m) ensure m.close end else ret = m end ret end
Calculated bit rate, also lazily loaded since we depend on the length
# File lib/ogginfo.rb, line 79 def bitrate @bitrate ||= (@filesize * 8).to_f / length() end
commits any tags to file
# File lib/ogginfo.rb, line 100 def close if tag != @original_tag path = File.join(Dir.tmpdir, "ruby-ogginfo_#{$$}.ogg") tempfile = File.new(path, "wb") File.open(@filename, "rb") do | input | replace_tags(input, tempfile, tag) end tempfile.close FileUtils.mv(path, @filename) end end
check the presence of a tag
# File lib/ogginfo.rb, line 114 def hastag? !tag.empty? end
Generated with the Darkfish Rdoc Generator 2.