class DiscId::Track

This class holds information about a single track.

Currently this includes the following fields:

You can access all fields either directly or with the square bracket notation:

track = Track.new(1, 150, 16007)
puts track.sectors   # 16007
puts track[:sectors] # 16007

@see DiscId::Disc#tracks

Attributes

isrc[R]

ISRC number of the track.

@note libdiscid >= 0.3.0 required. Older versions will always return nil.

Not available on all platforms, see
{http://musicbrainz.org/doc/libdiscid#Feature_Matrix}.

@return [String]

number[R]

The number of the track on the disc.

@return [Integer]

offset[R]

Start position of the track on the disc in sectors.

@return [Integer]

sectors[R]

Length of the track in sectors.

@return [Integer]

Public Class Methods

new(number, offset, sectors, isrc) click to toggle source

Initializes a new Track object.

# File lib/discid/track.rb, line 68
def initialize(number, offset, sectors, isrc)
  @number = number
  @offset = offset
  @sectors = sectors
  @isrc = isrc
end

Public Instance Methods

[](key) click to toggle source

Allows access to all fields similar to accessing values in a hash.

Example:

track = Track.new(1, 150, 16007)
puts track.sectors   # 16007
puts track[:sectors] # 16007
# File lib/discid/track.rb, line 110
def [](key)
  if [:number, :sectors, :offset, :end_sector,
      :seconds, :start_time, :end_time, :isrc].include?(key.to_sym)
    method(key).call
  end
end
end_sector() click to toggle source

End position of the track on the disc in sectors.

@return [Integer]

# File lib/discid/track.rb, line 78
def end_sector
  offset + sectors
end
end_time() click to toggle source

End position of the track on the disc in seconds.

@return [Integer]

# File lib/discid/track.rb, line 99
def end_time
  DiscId.sectors_to_seconds(end_sector)
end
seconds() click to toggle source

Length of the track in seconds.

@return [Integer]

# File lib/discid/track.rb, line 85
def seconds
  DiscId.sectors_to_seconds(sectors)
end
start_time() click to toggle source

Start position of the track on the disc in seconds.

@return [Integer]

# File lib/discid/track.rb, line 92
def start_time
  DiscId.sectors_to_seconds(offset)
end
to_hash() click to toggle source

Converts the Track into a Hash.

@return [Hash]

# File lib/discid/track.rb, line 120
def to_hash
  {
    :number       => number,
    :sectors      => sectors,
    :offset       => offset,
    :end_sector   => end_sector,
    :seconds      => seconds,
    :start_time   => start_time,
    :end_time     => end_time,
    :isrc         => isrc,
  }
end