Class: MusicBrainz::DiscID::TrackInfo
- Inherits:
-
Object
- Object
- MusicBrainz::DiscID::TrackInfo
- Defined in:
- lib/mb-discid.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.
- start_sector
-
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.
You can access all fields either with directly or with the square bracket notation:
track = TrackInfo.new(1, 150, 16007)
puts track.sectors # 16007
puts track[:sectors] # 16007
- See
-
DiscID#track_details
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
The number of the track on the disc.
-
#sectors ⇒ Object
readonly
Length of the track in sectors.
-
#start_sector ⇒ Object
readonly
Start position of the track on the disc in sectors.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Allows access to all fields similar to accessing values in a hash.
-
#end_sector ⇒ Object
End position of the track on the disc in sectors.
-
#end_time ⇒ Object
End position of the track on the disc in seconds.
-
#initialize(number, offset, length) ⇒ TrackInfo
constructor
Returns a new TrackInfo.
-
#seconds ⇒ Object
Length of the track in seconds.
-
#start_time ⇒ Object
Start position of the track on the disc in seconds.
-
#to_hash ⇒ Object
Converts the TrackInfo into a Hash.
Constructor Details
#initialize(number, offset, length) ⇒ TrackInfo
Returns a new TrackInfo.
126 127 128 129 130 |
# File 'lib/mb-discid.rb', line 126 def initialize(number, offset, length) @number = number @start_sector = offset @sectors = length end |
Instance Attribute Details
#number ⇒ Object (readonly)
The number of the track on the disc.
117 118 119 |
# File 'lib/mb-discid.rb', line 117 def number @number end |
#sectors ⇒ Object (readonly)
Length of the track in sectors.
120 121 122 |
# File 'lib/mb-discid.rb', line 120 def sectors @sectors end |
#start_sector ⇒ Object (readonly)
Start position of the track on the disc in sectors.
123 124 125 |
# File 'lib/mb-discid.rb', line 123 def start_sector @start_sector end |
Instance Method Details
#[](key) ⇒ Object
Allows access to all fields similar to accessing values in a hash.
Example:
track = TrackInfo.new(1, 150, 16007)
puts track.sectors # 16007
puts track[:sectors] # 16007
158 159 160 161 162 163 |
# File 'lib/mb-discid.rb', line 158 def [](key) if [:number, :sectors, :start_sector, :end_sector, :seconds, :start_time, :end_time].include?(key.to_sym) method(key).call end end |
#end_sector ⇒ Object
End position of the track on the disc in sectors.
133 134 135 |
# File 'lib/mb-discid.rb', line 133 def end_sector start_sector + sectors end |
#end_time ⇒ Object
End position of the track on the disc in seconds.
148 149 150 |
# File 'lib/mb-discid.rb', line 148 def end_time DiscID.sectors_to_seconds(end_sector) end |
#seconds ⇒ Object
Length of the track in seconds.
138 139 140 |
# File 'lib/mb-discid.rb', line 138 def seconds DiscID.sectors_to_seconds(sectors) end |
#start_time ⇒ Object
Start position of the track on the disc in seconds.
143 144 145 |
# File 'lib/mb-discid.rb', line 143 def start_time DiscID.sectors_to_seconds(start_sector) end |
#to_hash ⇒ Object
Converts the TrackInfo into a Hash.
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/mb-discid.rb', line 166 def to_hash { :sectors => sectors, :start_sector => start_sector, :end_sector => end_sector, :seconds => seconds, :start_time => start_time, :end_time => end_time, } end |