Class: MusicBrainz::Model::ISRC

Inherits:
Object
  • Object
show all
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.

See

wiki.musicbrainz.org/ISRC

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

Class Method Summary collapse

Instance Method Summary collapse

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

#countryObject (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

#designationObject (readonly)

Designation code (5 digits)



41
42
43
# File 'lib/rbrainz/model/isrc.rb', line 41

def designation
  @designation
end

#registrantObject (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

#yearObject (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

Returns:

  • (Boolean)


92
93
94
# File 'lib/rbrainz/model/isrc.rb', line 92

def eql?(other)
  self.to_s == ISRC.parse(other).to_s
end

#to_sObject

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_strObject

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