class MusicIds::GRid

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 en.wikipedia.org/wiki/Global_Release_Identifier and 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

Public Class Methods

id_blocks() click to toggle source

See www.ifpi.org/downloads/GRid_Standard_v2_1.pdf §5

# 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() click to toggle source

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

# File lib/music_ids/grid.rb, line 47
def self.prefix
  @prefix ||= 'GRID'.freeze
end

Public Instance Methods

as_full() click to toggle source

Generate the hyphen-separated full display GRid string @return [String]

# File lib/music_ids/grid.rb, line 81
def as_full
  "#{scheme}-#{issuer}-#{release}-#{check}"
end
check() click to toggle source

Return the GRid’s check character. @return [String]

# File lib/music_ids/grid.rb, line 71
def check
  fetch(:@check) { |grid_string| grid_string[17,1] }
end
issuer() click to toggle source

Return the GRid’s 5-character issuer code @return [String]

# File lib/music_ids/grid.rb, line 59
def issuer
  fetch(:@issuer) { |grid_string| grid_string[2,5] }
end
release() click to toggle source

Return the GRid’s 10-character release number. @return [String]

# File lib/music_ids/grid.rb, line 65
def release
  fetch(:@release) { |grid_string| grid_string[7,10] }
end
scheme() click to toggle source

Return the GRid’s two-letter scheme identifier @return [String]

# File lib/music_ids/grid.rb, line 53
def scheme
  fetch(:@scheme) { |grid_string| grid_string[0,2] }
end
to_grid() click to toggle source
# File lib/music_ids/grid.rb, line 75
def to_grid
  self
end