Class: Vorbis::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/vorbis.rb

Overview

This class reads metadata (such as comments/tags and bitrate) from Vorbis audio files. Here’s an example of usage:

require 'vorbis'

Vorbis::Info.open('echoplex.ogg') do |info|
  info.comments[:artist].first #=> "Nine Inch Nails"
  info.comments[:title].first  #=> "Echoplex"
  info.sample_rate             #=> 44100
end

You may notice that for each comment field an array of values is available. This is because it is perfectly valid for a Vorbis file to have multiple artists, titles, or anything else.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, container = :ogg) {|_self| ... } ⇒ Info

Create a new Vorbis::Info object for reading metadata.

Yields:

  • (_self)

Yield Parameters:

  • _self (Vorbis::Info)

    the object that the method was called on



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vorbis.rb', line 24

def initialize(path, container=:ogg)
  if path.is_a? IO
    @io = path
  else
    @io = open(path, 'rb')
  end
  
  case container
  when :ogg
    init_ogg
  else
    raise "#{container.to_s} is not a supported container format"
  end
  
  @io.close
  
  yield self if block_given?
end

Instance Attribute Details

#bitrateObject (readonly)

Returns the value of attribute bitrate.



21
22
23
# File 'lib/vorbis.rb', line 21

def bitrate
  @bitrate
end

#channelsObject (readonly)

Returns the value of attribute channels.



21
22
23
# File 'lib/vorbis.rb', line 21

def channels
  @channels
end

#comment_headerObject (readonly)

Returns the value of attribute comment_header.



19
20
21
# File 'lib/vorbis.rb', line 19

def comment_header
  @comment_header
end

#commentsObject (readonly)

Returns the value of attribute comments.



20
21
22
# File 'lib/vorbis.rb', line 20

def comments
  @comments
end

#durationObject (readonly)

Returns the value of attribute duration.



21
22
23
# File 'lib/vorbis.rb', line 21

def duration
  @duration
end

#identification_headerObject (readonly)

Returns the value of attribute identification_header.



19
20
21
# File 'lib/vorbis.rb', line 19

def identification_header
  @identification_header
end

#nominal_bitrateObject (readonly)

Returns the value of attribute nominal_bitrate.



21
22
23
# File 'lib/vorbis.rb', line 21

def nominal_bitrate
  @nominal_bitrate
end

#sample_rateObject (readonly)

Returns the value of attribute sample_rate.



21
22
23
# File 'lib/vorbis.rb', line 21

def sample_rate
  @sample_rate
end

Class Method Details

.open(*args, &block) ⇒ Object



43
44
45
# File 'lib/vorbis.rb', line 43

def self.open(*args, &block)
  return self.new(*args, &block)
end