class DiscId::Track
This class holds information about a single track.
Currently this includes the following fields:
-
number: The number of the track on the disc.
-
sectors: Length of the track in sectors.
-
offset: Start position of the track on the disc in sectors.
-
end_sector
: End position of the track on the disc in sectors. -
seconds: Length of the track in seconds.
-
start_time
: Start position of the track on the disc in seconds. -
end_time
: End position of the track on the disc in seconds. -
isrc: The track's ISRC (International Standard Recordings Code)
if available.
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 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]
The number of the track on the disc.
@return [Integer]
Start position of the track on the disc in sectors.
@return [Integer]
Length of the track in sectors.
@return [Integer]
Public Class Methods
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
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 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 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
Length of the track in seconds.
@return [Integer]
# File lib/discid/track.rb, line 85 def seconds DiscId.sectors_to_seconds(sectors) end
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
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