Class: DiscId::Track
- Inherits:
-
Object
- Object
- DiscId::Track
- Defined in:
- lib/discid/track.rb
Overview
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
Instance Attribute Summary collapse
-
#isrc ⇒ String
readonly
ISRC number of the track.
-
#number ⇒ Integer
readonly
The number of the track on the disc.
-
#offset ⇒ Integer
readonly
Start position of the track on the disc in sectors.
-
#sectors ⇒ Integer
readonly
Length of the track in sectors.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Allows access to all fields similar to accessing values in a hash.
-
#end_sector ⇒ Integer
End position of the track on the disc in sectors.
-
#end_time ⇒ Integer
End position of the track on the disc in seconds.
-
#initialize(number, offset, sectors, isrc) ⇒ Track
constructor
Initializes a new Track object.
-
#seconds ⇒ Integer
Length of the track in seconds.
-
#start_time ⇒ Integer
Start position of the track on the disc in seconds.
-
#to_hash ⇒ Hash
Converts the Track into a Hash.
Constructor Details
#initialize(number, offset, sectors, isrc) ⇒ Track
Initializes a new Track object.
68 69 70 71 72 73 |
# File 'lib/discid/track.rb', line 68 def initialize(number, offset, sectors, isrc) @number = number @offset = offset @sectors = sectors @isrc = isrc end |
Instance Attribute Details
#isrc ⇒ String (readonly)
libdiscid >= 0.3.0 required. Older versions will always return nil. Not available on all platforms, see http://musicbrainz.org/doc/libdiscid#Feature_Matrix.
ISRC number of the track.
65 66 67 |
# File 'lib/discid/track.rb', line 65 def isrc @isrc end |
#number ⇒ Integer (readonly)
The number of the track on the disc.
46 47 48 |
# File 'lib/discid/track.rb', line 46 def number @number end |
#offset ⇒ Integer (readonly)
Start position of the track on the disc in sectors.
56 57 58 |
# File 'lib/discid/track.rb', line 56 def offset @offset end |
#sectors ⇒ Integer (readonly)
Length of the track in sectors.
51 52 53 |
# File 'lib/discid/track.rb', line 51 def sectors @sectors end |
Instance Method Details
#[](key) ⇒ Object
110 111 112 113 114 115 |
# 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 ⇒ Integer
End position of the track on the disc in sectors.
78 79 80 |
# File 'lib/discid/track.rb', line 78 def end_sector offset + sectors end |
#end_time ⇒ Integer
End position of the track on the disc in seconds.
99 100 101 |
# File 'lib/discid/track.rb', line 99 def end_time DiscId.sectors_to_seconds(end_sector) end |
#seconds ⇒ Integer
Length of the track in seconds.
85 86 87 |
# File 'lib/discid/track.rb', line 85 def seconds DiscId.sectors_to_seconds(sectors) end |
#start_time ⇒ Integer
Start position of the track on the disc in seconds.
92 93 94 |
# File 'lib/discid/track.rb', line 92 def start_time DiscId.sectors_to_seconds(offset) end |
#to_hash ⇒ Hash
Converts the Track into a Hash.
120 121 122 123 124 125 126 127 128 129 130 131 |
# 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 |