Class: MusicBrainz::Model::ISRC
- Inherits:
-
Object
- Object
- MusicBrainz::Model::ISRC
- Defined in:
- lib/rbrainz/model/isrc.rb
Overview
Represents an International Standard Recording Code (ISRC).
The International Standard Recording Code or short ISRC is an identification system for audio and music video recordings. It is standarized by the IFPI in ISO 3901:2001 and used by IFPI members to assign unique identifiers to every distinct recording they release.
Constant Summary collapse
- ISRC_PATTERN =
/^([0-9A-Z]{2})-?([0-9A-Z]{3})-?([0-9A-Z]{2})-?([0-9A-Z]{5})$/i
Instance Attribute Summary collapse
-
#country ⇒ Object
readonly
2-letter country code according to the ISO 3166-1-Alpha-2 standard.
-
#designation ⇒ Object
readonly
Designation code (5 digits).
-
#registrant ⇒ Object
readonly
The Registrant Code identifies the entity assigning the Designation Code in an ISRC.
-
#year ⇒ Object
readonly
Year of reference (2 digits).
Class Method Summary collapse
-
.parse(obj) ⇒ Object
Tries to convert obj into an ISRC object.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Compares this ISRC with another one.
-
#initialize(isrc) ⇒ ISRC
constructor
Create a new ISRC object from the given string.
-
#to_s ⇒ Object
Convert this ISRC into a String.
-
#to_str ⇒ Object
Convert this ISRC into a String.
Constructor Details
#initialize(isrc) ⇒ ISRC
Create a new ISRC object from the given string.
- Raises
-
InvalidISRCError
60 61 62 63 64 65 66 67 68 |
# File 'lib/rbrainz/model/isrc.rb', line 60 def initialize(isrc) unless isrc.to_s =~ ISRC_PATTERN raise InvalidISRCError end @country = $1.upcase @registrant = $2.upcase @year = $3.upcase @designation = $4.upcase end |
Instance Attribute Details
#country ⇒ Object (readonly)
2-letter country code according to the ISO 3166-1-Alpha-2 standard.
32 33 34 |
# File 'lib/rbrainz/model/isrc.rb', line 32 def country @country end |
#designation ⇒ Object (readonly)
Designation code (5 digits)
41 42 43 |
# File 'lib/rbrainz/model/isrc.rb', line 41 def designation @designation end |
#registrant ⇒ Object (readonly)
The Registrant Code identifies the entity assigning the Designation Code in an ISRC.
35 36 37 |
# File 'lib/rbrainz/model/isrc.rb', line 35 def registrant @registrant end |
#year ⇒ Object (readonly)
Year of reference (2 digits).
38 39 40 |
# File 'lib/rbrainz/model/isrc.rb', line 38 def year @year end |
Class Method Details
.parse(obj) ⇒ Object
Tries to convert obj into an ISRC object.
If obj is an ISRC it is returned. Otherwise a new ISRC object is created by converting obj into a string and parsing it.
- Raises
-
InvalidISRCError
49 50 51 52 53 54 55 |
# File 'lib/rbrainz/model/isrc.rb', line 49 def self.parse(obj) if obj.is_a? ISRC return obj else return ISRC.new(obj) end end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Compares this ISRC with another one.
If other is not of the type ISRC an attempt is made to convert it into one. This may cause an InvalidISRCError to be raised. Please note that comparing an ISRC with a different type of object is usually not commutative.
- Raises
-
InvalidISRCError
92 93 94 |
# File 'lib/rbrainz/model/isrc.rb', line 92 def eql?(other) self.to_s == ISRC.parse(other).to_s end |
#to_s ⇒ Object
Convert this ISRC into a String. Will return the readable version of the ISRC with dashes added, e.g. FR-Z03-91-01231
73 74 75 |
# File 'lib/rbrainz/model/isrc.rb', line 73 def to_s return [@country, @registrant, @year, @designation].join('-') end |
#to_str ⇒ Object
Convert this ISRC into a String. Will return the 12 character representation of the ISRC without dashes, e.g. FRZ039101231
80 81 82 |
# File 'lib/rbrainz/model/isrc.rb', line 80 def to_str return [@country, @registrant, @year, @designation].join end |