music_ids 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d75caff64b4e4891c3f7ec2f74cd69565326ad32
4
+ data.tar.gz: ce0f8a0238c334c6f9fae24e73d2a4e56c0047d9
5
+ SHA512:
6
+ metadata.gz: 8c011793f6cc32c44a74add1a360e30c6b1c44791c145500ac1ac75b154a7d0dfed11e852d118035f55a564d6813ee9ad9c22a071da9c7bcf41998d03fa27f30
7
+ data.tar.gz: 5ba4a46d7e81136e56299c0f6e1247735f133108527587305d55c8f492dbbb39e09e443a197e1e819001f775bba22500cef8ddadded324ca30c2bb8228cba4fd
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in music_ids.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'codeclimate-test-reporter', require: false
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 tape.tv AG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # MusicIds
2
+
3
+ `music_ids` contains classes that represent some of the main ID formats in use in the music industry for identifying individual pieces of recorded music.
4
+
5
+ There are often several ways that these IDs can be written, so the classes provide standard APIs to parse and normalise ID strings, as well as to break them into their components.
6
+
7
+ Currently we offer a class for the ISRC (International Standard Recording Code).
8
+
9
+ ## Installation
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'music_ids'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install music_ids
23
+
24
+ ## Usage
25
+ (See API docs at <http://www.rubydoc.info/gems/music_ids> for more details including links to the relevant ID specifications.)
26
+
27
+ ```ruby
28
+ require 'music_ids'
29
+
30
+ isrc = MusicIds::ISRC.parse('FRZ039800212')
31
+ isrc.country #=> 'FR'
32
+ isrc.registrant #=> 'Z03'
33
+ isrc.year #=> '98'
34
+ isrc.designation #=> '00212'
35
+
36
+ other = ISRC.parse('FR-Z03-98-00212')
37
+ other.registrant #=> 'Z03'
38
+
39
+ isrc == other #=> true
40
+
41
+ isrc.to_s #=> 'FRZ039800212'
42
+ isrc.as(:full) #=> 'FR-Z03-98-00212'
43
+ ```
44
+
45
+ ## Development
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+ 1. Fork it ( https://github.com/[my-github-username]/music_ids/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ rescue LoadError
10
+ # no rspec available
11
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "music_ids"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,156 @@
1
+ module MusicIds
2
+ # The ISRC class represents an International Standard Recording Code, and
3
+ # provides simple methods to parse and re-present them.
4
+ #
5
+ # == What is an ISRC?
6
+ # An ISRC is a globally unique ID for an audio / video recording of a piece
7
+ # of music. (That is, two different recordings of the same song should have
8
+ # different ISRCs)
9
+ #
10
+ # ISRCs consist of four blocks of information: a two-letter country code,
11
+ # three-character registrant code, two-digit year (see #year), and five-digit
12
+ # designation code. There are two main string representations: the canonical
13
+ # 12-character version, and a 15-character version that inserts hyphens (-)
14
+ # between the blocks.
15
+ #
16
+ # The first two blocks identify, essentially, a record company / distributor
17
+ # and their country of origin, the last two blocks provide a unique recording
18
+ # number for that company in a particular year.
19
+ #
20
+ # You can get more details from
21
+ # https://en.wikipedia.org/wiki/International_Standard_Recording_Code and
22
+ # http://www.usisrc.org/
23
+ #
24
+ # == Well-formedness and validity
25
+ # ISRC's are supposed to be able to be looked
26
+ # up in a global database, so we need to draw a distinction between *valid*
27
+ # ISRC's, which are ISRC's we have looked up in that database and verified,
28
+ # and well-formed ISRC's, which is to say strings matching the requirements
29
+ # above.
30
+ #
31
+ # Checking or enforcing validity is beyond the scope of this class.
32
+ # Well-formedness, on the other hand, is easy to check and enforce.
33
+ #
34
+ # While you don't want to be emitting badly-formed ISRCs, if you handle
35
+ # ISRC's from elsewhere you may well run across bad metadata that you need to
36
+ # preserve, but probably want to be aware of the fact that it's bad.
37
+ #
38
+ # To help with that there are two parsing modes, strict (the default), and
39
+ # relaxed.
40
+ #
41
+ # In strict parsing mode, <tt>ISRC.parse</tt> will raise an error if passed a
42
+ # badly-formed ISRC string. In relaxed mode, it will return an <tt>ISRC</tt>
43
+ # instance that will return <tt>false</tt> from <tt>#ok?</tt> and will return
44
+ # nil from all the component methods like <tt>#registrant</tt>
45
+ class ISRC
46
+ # See http://www.ifpi.org/content/library/isrc_handbook.pdf §3.5
47
+ WELL_FORMED_INPUT = /\A[A-Z]{2}-?[A-Z0-9]{3}-?[0-9]{2}-?[0-9]{5}\Z/
48
+
49
+ class << self
50
+ # Parse an ISRC string into an ISRC instance
51
+ #
52
+ # @param input [String] The input ISRC string to parse
53
+ # @param opts [Hash] Parsing options
54
+ # @option opts [true, false] :relaxed (false) Whether to parse in relaxed mode
55
+ # @return [ISRC] the ISRC instance
56
+ def parse(input, opts = {})
57
+ input = input.to_s.upcase
58
+ opts[:relaxed] ? parse_relaxed(input) : parse_strict(input)
59
+ end
60
+
61
+ private
62
+
63
+ def parse_strict(input)
64
+ if WELL_FORMED_INPUT.match(input)
65
+ new(input.gsub('-', ''))
66
+ else
67
+ raise ArgumentError, "'#{input}' is not the right length to be a 12- or 15-character ISRC"
68
+ end
69
+ end
70
+
71
+ def parse_relaxed(input)
72
+ if WELL_FORMED_INPUT.match(input)
73
+ new(input.gsub('-', ''))
74
+ else
75
+ new(input, ok: false)
76
+ end
77
+ end
78
+ end
79
+
80
+ # @api private
81
+ # @param isrc_string [String] The ISRC string
82
+ # @param opts [Hash]
83
+ # @option opts [true, false] :ok (true) Whether the ISRC is well-formed or not
84
+ def initialize(isrc_string, opts = {ok: true})
85
+ @isrc_string = isrc_string.dup.freeze
86
+ @ok = opts[:ok] ? true : false
87
+ end
88
+
89
+ # Is this a well-formed ISRC?
90
+ # @return [true,false]
91
+ def ok?
92
+ @ok
93
+ end
94
+
95
+ # Return the ISRC's two-letter country code
96
+ # @return [String]
97
+ def country
98
+ return unless ok?
99
+ @country ||= @isrc_string[0,2].freeze
100
+ end
101
+
102
+ # Return the ISRC's three-character registrant code
103
+ # @return [String]
104
+ def registrant
105
+ return unless ok?
106
+ @registrant ||= @isrc_string[2,3].freeze
107
+ end
108
+
109
+ # Return the ISRC's two-digit year.
110
+ #
111
+ # Note that year > 40 is a 19YY year, and 00 to 39 are 20YY years
112
+ # see http://www.ifpi.org/content/library/isrc_handbook.pdf section 4.8
113
+ # @return [String]
114
+ def year
115
+ return unless ok?
116
+ @year ||= @isrc_string[5,2].freeze
117
+ end
118
+
119
+ # Return the ISRC's five-character designation code.
120
+ #
121
+ # @return [String]
122
+ def designation
123
+ return unless ok?
124
+ @designation ||= @isrc_string[7,5].freeze
125
+ end
126
+
127
+ # return the ISRC as a normalised 12-character string
128
+ # @reuturn [String]
129
+ def to_s
130
+ @isrc_string.dup
131
+ end
132
+
133
+ def to_isrc
134
+ self
135
+ end
136
+
137
+ def ==(other)
138
+ to_s == other.to_s
139
+ end
140
+
141
+ # Returns the ISRC as a string, either the 12-character normalised string
142
+ # (:data) or the 15-character display string (:full). Note that a badly-formed ISRC will simply return the original string whichever format you ask for
143
+ # @param format [:data, :full] the output format to use
144
+ # @return [String]
145
+ def as(format)
146
+ case format
147
+ when :data
148
+ to_s
149
+ when :full
150
+ ok? ? "#{country}-#{registrant}-#{year}-#{designation}" : to_s
151
+ else
152
+ raise ArgumentError, "format must be one of [:data, :full], but it was #{format.inspect}"
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,3 @@
1
+ module MusicIds
2
+ VERSION = "0.1.0"
3
+ end
data/lib/music_ids.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "music_ids/version"
2
+
3
+ module MusicIds
4
+ # Your code goes here...
5
+ end
data/music_ids.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'music_ids/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "music_ids"
8
+ spec.version = MusicIds::VERSION
9
+ spec.authors = ["Matt Patterson"]
10
+ spec.email = ["matt@reprocessed.org"]
11
+
12
+ spec.summary = %q{A library to handle parsing, normalisation, and output of music industry ID formats like ISRC and GRid}
13
+ spec.description = %q{music_ids contains classes that represent some of the main ID formats in use in the music industry for identifying individual pieces of recorded music.
14
+
15
+ There are often several ways that these IDs can be written, so the classes provide standard APIs to parse and normalise ID strings, as well as to break them into their components.}
16
+ spec.homepage = "https://github.com/tape-tv/music_ids"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3"
27
+ spec.add_development_dependency "yard"
28
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: music_ids
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Patterson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |-
70
+ music_ids contains classes that represent some of the main ID formats in use in the music industry for identifying individual pieces of recorded music.
71
+
72
+ There are often several ways that these IDs can be written, so the classes provide standard APIs to parse and normalise ID strings, as well as to break them into their components.
73
+ email:
74
+ - matt@reprocessed.org
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".ruby-version"
82
+ - ".travis.yml"
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/music_ids.rb
91
+ - lib/music_ids/isrc.rb
92
+ - lib/music_ids/version.rb
93
+ - music_ids.gemspec
94
+ homepage: https://github.com/tape-tv/music_ids
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A library to handle parsing, normalisation, and output of music industry
118
+ ID formats like ISRC and GRid
119
+ test_files: []
120
+ has_rdoc: