grid-number 0.0.1

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: 07a08910f6014d347eeb2834b9b1324c4586adaa
4
+ data.tar.gz: 19bb9330c758f451eebfefc2ffd8446e1ce875c3
5
+ SHA512:
6
+ metadata.gz: 29e04abcc90a31be8ff5400a9e6e935079014038331d21301171ce6ea34ab0e55aa751422624ffba8173d2bcab80e5d567ee748b3d6360e85376fd8b5b8ec423
7
+ data.tar.gz: fbe0826f85d37b448f46198b9a07158983bc339ce1e5257ed65c11fe375eac60d0b3d4b72427f0fbefffb2e359dedb491db0be671d6f2817551a9fc65145dd6e
data/.gitignore ADDED
@@ -0,0 +1,123 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby,emacs
3
+
4
+ ### Emacs ###
5
+ # -*- mode: gitignore; -*-
6
+ *~
7
+ \#*\#
8
+ /.emacs.desktop
9
+ /.emacs.desktop.lock
10
+ *.elc
11
+ auto-save-list
12
+ tramp
13
+ .\#*
14
+
15
+ # Org-mode
16
+ .org-id-locations
17
+ *_archive
18
+
19
+ # flymake-mode
20
+ *_flymake.*
21
+
22
+ # eshell files
23
+ /eshell/history
24
+ /eshell/lastdir
25
+
26
+ # elpa packages
27
+ /elpa/
28
+
29
+ # reftex files
30
+ *.rel
31
+
32
+ # AUCTeX auto folder
33
+ /auto/
34
+
35
+ # cask packages
36
+ .cask/
37
+ dist/
38
+
39
+ # Flycheck
40
+ flycheck_*.el
41
+
42
+ # server auth directory
43
+ /server/
44
+
45
+ # projectiles files
46
+ .projectile
47
+ projectile-bookmarks.eld
48
+
49
+ # directory configuration
50
+ .dir-locals.el
51
+
52
+ # saveplace
53
+ places
54
+
55
+ # url cache
56
+ url/cache/
57
+
58
+ # cedet
59
+ ede-projects.el
60
+
61
+ # smex
62
+ smex-items
63
+
64
+ # company-statistics
65
+ company-statistics-cache.el
66
+
67
+ # anaconda-mode
68
+ anaconda-mode/
69
+
70
+ ### Ruby ###
71
+ *.gem
72
+ *.rbc
73
+ /.config
74
+ /coverage/
75
+ /InstalledFiles
76
+ /pkg/
77
+ /spec/reports/
78
+ /spec/examples.txt
79
+ /test/tmp/
80
+ /test/version_tmp/
81
+ /tmp/
82
+
83
+ # Used by dotenv library to load environment variables.
84
+ # .env
85
+
86
+ ## Specific to RubyMotion:
87
+ .dat*
88
+ .repl_history
89
+ build/
90
+ *.bridgesupport
91
+ build-iPhoneOS/
92
+ build-iPhoneSimulator/
93
+
94
+ ## Specific to RubyMotion (use of CocoaPods):
95
+ #
96
+ # We recommend against adding the Pods directory to your .gitignore. However
97
+ # you should judge for yourself, the pros and cons are mentioned at:
98
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
99
+ #
100
+ # vendor/Pods/
101
+
102
+ ## Documentation cache and generated files:
103
+ /.yardoc/
104
+ /_yardoc/
105
+ /doc/
106
+ /rdoc/
107
+
108
+ ## Environment normalization:
109
+ /.bundle/
110
+ /vendor/bundle
111
+ /lib/bundler/man/
112
+
113
+ # for a library or gem, you might want to ignore these files since the code is
114
+ # intended to run in multiple environments; otherwise, check them in:
115
+ Gemfile.lock
116
+ # .ruby-version
117
+ # .ruby-gemset
118
+
119
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
120
+ .rvmrc
121
+
122
+
123
+ # End of https://www.gitignore.io/api/ruby,emacs
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ before_install:
9
+ gem install bundler -v 1.14.6
10
+ notifications:
11
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grid_number.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Skye Shaw
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,71 @@
1
+ # GRid
2
+
3
+ [![Build Status](https://secure.travis-ci.org/ScreenStaring/grid-number.svg)](https://secure.travis-ci.org/ScreenStaring/grid-number)
4
+
5
+ Class for managing Global Release Identifiers (GRid numbers).
6
+ GRid numbers are used to identify electronic music releases.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "grid-number"
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install grid-number
23
+
24
+ ## Usage
25
+
26
+ ```rb
27
+ require "grid"
28
+
29
+ grid = GRid.parse("A12425GABC1234011K")
30
+ grid = GRid.parse("A1-2425G-ABC1234011-K")
31
+ grid = GRid.parse(" grid:A1-2425G-ABC1234011-K ")
32
+ grid.valid? # true
33
+ grid.id_scheme # A1
34
+ grid.issuer_code # 2425G
35
+ grid.release_number # ABC1234011
36
+ grid.check_character # K
37
+
38
+ grid = GRid.new(:issuer_code => "2425G", :release_number => "ABC1234002")
39
+ grid.check_character # M
40
+ grid.release_number = "X999150000"
41
+ grid.check_character # 3
42
+
43
+ grid = GRid.parse("A12425GABC1234011X") # Wrong check character
44
+ grid.valid? # false
45
+ grid.errors[:check_character] # ["verification failed"]
46
+
47
+ GRid.default_issuer_code = "2425G"
48
+ grid = GRid.new(:release_number => "ABC1234002")
49
+ grid.to_s # A12425GABC1234002M
50
+ grid.formatted # A1-2425G-ABC1234002-M
51
+ ```
52
+
53
+ ## Links
54
+
55
+ * [Global Release Identifier](https://en.wikipedia.org/wiki/Global_Release_Identifier)
56
+ * [Documentation](http://rdoc.info/gems/grid-number)
57
+ * [Homepage](https://github.com/ScreenStaring/grid-number)
58
+
59
+ ## See Also
60
+
61
+ * [DDEX](https://github.com/sshaw) - DDEX metadata serialization
62
+ * [istwox](https://github.com/malenkiki/istwox) - Classes for ISBN, ISSN, ISRC, ISMN and ISAN numbers
63
+ * [iTunes Store Transporter: GUI](http://transportergui.com) - GUI and workflow automation for the iTunes Store’s Transporter (`iTMSTransporter`)
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
68
+
69
+ ---
70
+
71
+ Made by [ScreenStaring](http://screenstaring.com)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "grid"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grid-number"
8
+ spec.version = GRid::VERSION
9
+ spec.authors = ["Skye Shaw"]
10
+ spec.email = ["skye.shaw@gmail.com"]
11
+
12
+ spec.summary = %q{Class to represent Global Release Identifiers (GRid numbers).}
13
+ spec.description = <<-DESC
14
+ Class to represent Global Release Identifiers (GRid numbers).
15
+ GRid numbers are used to identify electronic music releases.
16
+ DESC
17
+
18
+ spec.homepage = "https://github.com/ScreenStaring"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.14"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ end
@@ -0,0 +1 @@
1
+ require "grid"
data/lib/grid.rb ADDED
@@ -0,0 +1,225 @@
1
+ class GRid
2
+ VERSION = "0.0.1".freeze
3
+
4
+ DEFAULT_ID_SCHEME = "A1".freeze
5
+ CHECK_CODES = (("0".."9").to_a + ("A".."Z").to_a).freeze
6
+
7
+ attr_reader :id_scheme, :issuer_code, :release_number, :errors, :check_character
8
+
9
+ class << self
10
+ #
11
+ # The issuer code to use when instansating an instance and none is provided.
12
+ #
13
+ def default_issuer_code
14
+ @default_issuer_code
15
+ end
16
+
17
+ def default_issuer_code=(code)
18
+ @default_issuer_code = code
19
+ end
20
+
21
+ #
22
+ # Create an instance from +str+.
23
+ #
24
+ # grid = GRid.parse("A12425GABC1234002")
25
+ # grid = GRid.parse("A1-2425G-ABC1234002-M")
26
+ # grid = GRid.parse("grid:A1-2425G-ABC1234002-M")
27
+ #
28
+ # === Arguments
29
+ #
30
+ # [str (String)] The GRid to parse, does not have to be valid
31
+ #
32
+ # === Returns
33
+ #
34
+ # An instance of GRid representing +str+.
35
+ #
36
+ # === Errors
37
+ #
38
+ # No errors are raised. A GRid is always returned.
39
+ # To determine if it's valid call its #valid? method.
40
+ #
41
+ def parse(str)
42
+ return GRid.new if str.nil?
43
+
44
+ str = str.strip
45
+ return GRid.new if str.empty?
46
+
47
+ str.upcase!
48
+ str.sub!(/\AGRID:/, "")
49
+
50
+ extract = lambda do |i, j|
51
+ val = str[i, j]
52
+ return unless val
53
+
54
+ # 2.5 has delete_prefix
55
+ str[i, j] = ""
56
+ str.sub!(/\A-/, "")
57
+
58
+ val
59
+ end
60
+
61
+ GRid.new(:id_scheme => extract[0, 2],
62
+ :issuer_code => extract[0, 5],
63
+ :release_number => extract[0, 10],
64
+ :check_character => extract[-1, 1])
65
+ end
66
+ end
67
+
68
+ #
69
+ # Create a new instance consisting of +parts+.
70
+ # The #check_character will be calculated if none is given.
71
+ #
72
+ # === Arguments
73
+ #
74
+ # [parts (Hash)] Parts of the GRid, optional
75
+ #
76
+ # === Parts
77
+ #
78
+ # All parts are optional.
79
+ #
80
+ # [:id_scheme (String)] ID scheme portion, defaults to +A1+
81
+ # [:issuer_code (String)] Issuer code portion, defaults to default_issuer_code
82
+ # [:release_number (String)] Release number portion
83
+ # [:check_character (String)] Check character portion, will be calculated if not given
84
+ #
85
+
86
+ def initialize(parts = nil)
87
+ parts ||= {}
88
+
89
+ @issuer_code = parts[:issuer_code]
90
+ @issuer_code = self.class.default_issuer_code.dup if @issuer_code.nil? && self.class.default_issuer_code
91
+ @release_number = parts[:release_number]
92
+ @id_scheme = parts[:id_scheme] || DEFAULT_ID_SCHEME.dup
93
+ @check_character = parts[:check_character] || calculate_check_character
94
+
95
+ @errors = {}
96
+ end
97
+
98
+ %w[id_scheme issuer_code release_number].each do |name|
99
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
100
+ def #{name}=(s)
101
+ @#{name} = s
102
+ @check_character = calculate_check_character
103
+ @#{name}
104
+ end
105
+ METHOD
106
+ end
107
+
108
+ #
109
+ # Validate the GRid. To get the errors call #errors.
110
+ #
111
+ # if !grid.valid?
112
+ # grid.errors.each do |attr, errors|
113
+ # printf "%10s: %s", attr, errors.join(", ")
114
+ # end
115
+ # end
116
+ #
117
+ def valid?
118
+ errors.clear
119
+
120
+ validate_id_scheme!
121
+ validate_issuer_code!
122
+ validate_release_number!
123
+ validate_check_character!
124
+
125
+ errors.empty?
126
+ end
127
+
128
+ #
129
+ # Create a Hash representing the GRid. Keys are Symbols representing the portions of the GRid.
130
+ #
131
+ def to_h
132
+ { :id_scheme => id_scheme,
133
+ :issuer_code => issuer_code,
134
+ :release_number => release_number,
135
+ :check_character => check_character }
136
+ end
137
+
138
+ #
139
+ # Return a formatted +String+ representation of the GRid.
140
+ #
141
+ def formatted
142
+ [ id_scheme, issuer_code, release_number, check_character ].compact.join("-").upcase
143
+ end
144
+
145
+ def to_s
146
+ [ id_scheme, issuer_code, release_number, check_character ].compact.join("").upcase
147
+ end
148
+
149
+ def ==(other)
150
+ other = self.class.parse(other) if other.is_a?(String)
151
+ eql?(other)
152
+ end
153
+
154
+ def eql?(other)
155
+ other.instance_of?(self.class) && to_s == other.to_s
156
+ end
157
+
158
+ def hash
159
+ to_s.hash
160
+ end
161
+
162
+ private
163
+
164
+ def validate_id_scheme!
165
+ if id_scheme != DEFAULT_ID_SCHEME
166
+ errors[:id_scheme] = ["must be #{DEFAULT_ID_SCHEME}"]
167
+ end
168
+ end
169
+
170
+ def validate_issuer_code!
171
+ messages = []
172
+
173
+ if issuer_code.nil?
174
+ messages << "required"
175
+ elsif issuer_code !~ /\A[a-z0-9]{5}\z/i
176
+ messages << "must be 5 alphanumeric characters"
177
+ end
178
+
179
+ errors[:issuer_code] = messages if messages.any?
180
+ end
181
+
182
+ def validate_release_number!
183
+ messages = []
184
+
185
+ if release_number.nil?
186
+ messages << "required"
187
+ elsif release_number !~ /\A[a-z0-9]{10}\z/i
188
+ messages << "must be 10 alphanumeric characters"
189
+ end
190
+
191
+ errors[:release_number] = messages if messages.any?
192
+ end
193
+
194
+ def validate_check_character!
195
+ messages = []
196
+
197
+ if check_character.nil?
198
+ messages << "required"
199
+ elsif check_character != calculate_check_character
200
+ messages << "verification failed"
201
+ end
202
+
203
+ errors[:check_character] = messages if messages.any?
204
+ end
205
+
206
+ def calculate_check_character
207
+ value = to_s[0, 17]
208
+ char = 36
209
+
210
+ 0.upto(value.size - 1) do |lng|
211
+ v = CHECK_CODES.index(value[lng])
212
+ return unless v
213
+
214
+ char += v
215
+ char -= 36 if char > 36
216
+ char *= 2
217
+ char -= 37 if char >= 37
218
+ end
219
+
220
+ char = 37 - char
221
+ char = 0 if char == 36
222
+
223
+ CHECK_CODES[char]
224
+ end
225
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grid-number
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Skye Shaw
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-08 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: |2
56
+ Class to represent Global Release Identifiers (GRid numbers).
57
+ GRid numbers are used to identify electronic music releases.
58
+ email:
59
+ - skye.shaw@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - grid-number.gemspec
71
+ - lib/grid-number.rb
72
+ - lib/grid.rb
73
+ homepage: https://github.com/ScreenStaring
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.6.12
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Class to represent Global Release Identifiers (GRid numbers).
97
+ test_files: []