Class: MusicIds::GRid

Inherits:
Object
  • Object
show all
Includes:
Id
Defined in:
lib/music_ids/grid.rb

Overview

The GRid class represents a Global Release Identifier, and provides simple methods to parse and re-present them.

What is a GRid?

GRid's are unique identifiers for Releases of recorded music, as distinct from different Products (See the GRid Handbook for more details). They're often used as key identifiers in the delivery and reporting of digital music products.

You can get more details from https://en.wikipedia.org/wiki/Global_Release_Identifier and http://www.ifpi.org/grid.php

Well-formedness and validity

GRid's are supposed to be able to be looked up in a global database, so we need to draw a distinction between valid GRid's, which are GRid's we have looked up and verified in that database, and well-formed GRid's, which are just strings that match the requirements above.

Checking or enforcing validity is beyond the scope of this class. Well-formedness, on the other hand, is easy to check and enforce.

While you don't want to be emitting badly-formed GRid's, if you handle GRid's from elsewhere you may well run across bad metadata that you need to preserve, but probably want to be aware of the fact that it's bad.

To help with that there are two parsing modes, strict (the default), and relaxed.

In strict parsing mode, GRid.parse will raise an error if passed a badly-formed GRid string. In relaxed mode, it will return an GRid instance that will return false from #ok? and will return nil from all the component methods like #issuer

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Id

#==, #as, #as_json, included, #initialize, #ok?, #prefix, #to_s

Class Method Details

.id_blocks ⇒ Object



41
42
43
# File 'lib/music_ids/grid.rb', line 41

def self.id_blocks
  ['A1', '[A-Z0-9]{5}', '[A-Z0-9]{10}', '[A-Z0-9]']
end

.prefix ⇒ Object

The prefix to use for generating a prefixed string representation of the GRID (see http://www.ifpi.org/downloads/GRid_Standard_v2_1.pdf §6



47
48
49
# File 'lib/music_ids/grid.rb', line 47

def self.prefix
  @prefix ||= 'GRID'.freeze
end

Instance Method Details

#as_full ⇒ String

Generate the hyphen-separated full display GRid string

Returns:

  • (String)


81
82
83
# File 'lib/music_ids/grid.rb', line 81

def as_full
  "#{scheme}-#{issuer}-#{release}-#{check}"
end

#check ⇒ String

Return the GRid's check character.

Returns:

  • (String)


71
72
73
# File 'lib/music_ids/grid.rb', line 71

def check
  fetch(:@check) { |grid_string| grid_string[17,1] }
end

#issuer ⇒ String

Return the GRid's 5-character issuer code

Returns:

  • (String)


59
60
61
# File 'lib/music_ids/grid.rb', line 59

def issuer
  fetch(:@issuer) { |grid_string| grid_string[2,5] }
end

#release ⇒ String

Return the GRid's 10-character release number.

Returns:

  • (String)


65
66
67
# File 'lib/music_ids/grid.rb', line 65

def release
  fetch(:@release) { |grid_string| grid_string[7,10] }
end

#scheme ⇒ String

Return the GRid's two-letter scheme identifier

Returns:

  • (String)


53
54
55
# File 'lib/music_ids/grid.rb', line 53

def scheme
  fetch(:@scheme) { |grid_string| grid_string[0,2] }
end

#to_grid ⇒ Object



75
76
77
# File 'lib/music_ids/grid.rb', line 75

def to_grid
  self
end