Class: DiscId::Disc
- Inherits:
-
Object
- Object
- DiscId::Disc
- Defined in:
- lib/discid/disc.rb
Overview
This class holds information about a disc (TOC, MCN, ISRCs).
Use #read or #put to initialize an instance of Disc.
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
The device from which this disc object was read.
Instance Method Summary collapse
-
#first_track_number ⇒ Integer
The number of the first track on this disc.
-
#freedb_id ⇒ String
The FreeDB DiscID.
-
#id ⇒ String
The MusicBrainz DiscID.
-
#last_track_number ⇒ Integer
The number of the last track on this disc.
-
#mcn ⇒ String
The media catalogue number on the disc, if present.
-
#seconds ⇒ Integer
The length of the disc in seconds.
-
#sectors ⇒ Integer
The length of the disc in sectors.
-
#submission_url ⇒ String
An URL for submitting the DiscID to MusicBrainz.
-
#to_s ⇒ String
DiscID to String conversion.
-
#toc_string ⇒ String
Return a string representing CD Table Of Contents (TOC).
-
#tracks {|track_info| ... } ⇒ Array<Track>
Returns an array of Track objects.
Instance Attribute Details
#device ⇒ Object (readonly)
The device from which this disc object was read.
28 29 30 |
# File 'lib/discid/disc.rb', line 28 def device @device end |
Instance Method Details
#first_track_number ⇒ Integer
The number of the first track on this disc.
94 95 96 |
# File 'lib/discid/disc.rb', line 94 def first_track_number return Lib.get_first_track_num @handle if @read end |
#freedb_id ⇒ String
The FreeDB DiscID.
87 88 89 |
# File 'lib/discid/disc.rb', line 87 def freedb_id return Lib.get_freedb_id @handle if @read end |
#id ⇒ String
The MusicBrainz DiscID.
80 81 82 |
# File 'lib/discid/disc.rb', line 80 def id return Lib.get_id @handle if @read end |
#last_track_number ⇒ Integer
The number of the last track on this disc.
101 102 103 |
# File 'lib/discid/disc.rb', line 101 def last_track_number return Lib.get_last_track_num @handle if @read end |
#mcn ⇒ String
libdiscid >= 0.3.0 required. Older versions will always return nil. Not available on all platforms, see http://musicbrainz.org/doc/libdiscid#Feature_Matrix.
The media catalogue number on the disc, if present.
Requires libdiscid >= 0.5. If not supported this method will always
return nil
.
129 130 131 |
# File 'lib/discid/disc.rb', line 129 def mcn return Lib.get_mcn @handle if @read end |
#seconds ⇒ Integer
The length of the disc in seconds.
115 116 117 |
# File 'lib/discid/disc.rb', line 115 def seconds DiscId.sectors_to_seconds(sectors) if @read end |
#sectors ⇒ Integer
The length of the disc in sectors.
108 109 110 |
# File 'lib/discid/disc.rb', line 108 def sectors return Lib.get_sectors @handle if @read end |
#submission_url ⇒ String
An URL for submitting the DiscID to MusicBrainz.
The URL leads to an interactive disc submission wizard that guides the user through the process of associating this disc's DiscID with a release in the MusicBrainz database.
170 171 172 |
# File 'lib/discid/disc.rb', line 170 def submission_url return Lib.get_submission_url @handle if @read end |
#to_s ⇒ String
DiscID to String conversion. Same as calling the method #id but guaranteed to return a string.
179 180 181 |
# File 'lib/discid/disc.rb', line 179 def to_s id.to_s end |
#toc_string ⇒ String
Return a string representing CD Table Of Contents (TOC).
The TOC suitable as value of the toc parameter when accessing the MusicBrainz Web Service. This enables fuzzy searching when the actual DiscID is not found.
Note that this is the unencoded value, which still contains spaces.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/discid/disc.rb', line 146 def toc_string return nil if not @read result = Lib.get_toc_string if not result # probably an old version of libdiscid (< 0.6.0) # gather toc string from submission_url match = /toc=([0-9+]+)/.match self.submission_url if match result = match[1].gsub("+", " ") else raise "can't get toc string from submission url" end end return result end |
#tracks {|track_info| ... } ⇒ Array<Track>
Returns an array of Track objects. Each Track object contains detailed information about the track.
Returns always nil
if no ID was yet read. The block won't be
called in this case.
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/discid/disc.rb', line 193 def tracks if @read read_tracks if @tracks.nil? if block_given? @tracks.each(&Proc.new) return nil else return @tracks end end end |