isni 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG +2 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +35 -0
- data/Rakefile +11 -0
- data/lib/isni.rb +50 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 377dcc23aef9b2c95633d4cb5c9c1e8352dbe04d
|
4
|
+
data.tar.gz: 13512e9cfc1c1526b53d991c3b305cbc32c6d0a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f927d203e32ed77938351662c3405364aa80114d47199d0010b992c721f03598bbe1bda97a0fb7d1ebcdad64b53a33b873c12b9963c4f14d343f728eee32e5c0
|
7
|
+
data.tar.gz: b239687d6f6df4b7a157407155fa47b1878dc13d6fbcdb8fab5f8fe09fa6f4604e42402ca8bcb92b0c59983879a4357a326adea126bdb18ceec4656d21cfb83c
|
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Peter Yandell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
A small class for generating and validating Internation Standard Name
|
2
|
+
Identifiers (ISNI). This will also work just fine with ORCID, a subset
|
3
|
+
of ISNI.
|
4
|
+
|
5
|
+
= Installation
|
6
|
+
|
7
|
+
gem install isni
|
8
|
+
|
9
|
+
= Usage
|
10
|
+
|
11
|
+
ISNI.new("000000029534656X").valid?
|
12
|
+
=> true
|
13
|
+
|
14
|
+
ISNI.valid?("000000029534656X")
|
15
|
+
=> true
|
16
|
+
|
17
|
+
ISNI.valid?("0000000295346560")
|
18
|
+
=> false
|
19
|
+
|
20
|
+
ISNI.complete("000000029534656")
|
21
|
+
=> "000000029534656X"
|
22
|
+
|
23
|
+
ISNI.new("000000029534656X").to_s
|
24
|
+
=> "0000-0002-9534-656X"
|
25
|
+
|
26
|
+
= Further Reading
|
27
|
+
|
28
|
+
- http://en.wikipedia.org/wiki/International_Standard_Name_Identifier
|
29
|
+
- http://orcid.org/
|
30
|
+
- http://support.orcid.org/knowledgebase/articles/116780-structure-of-the-orcid-identifier
|
31
|
+
|
32
|
+
= Contributing
|
33
|
+
|
34
|
+
Source code is publicly available @ http://github.com/yob/isni.
|
35
|
+
Patches welcome, preferably via a git repo I can pull from.
|
data/Rakefile
ADDED
data/lib/isni.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
class ISNI
|
2
|
+
|
3
|
+
def initialize(str)
|
4
|
+
@number = str.to_s.gsub(/[^\dxX]/, "")
|
5
|
+
end
|
6
|
+
|
7
|
+
def valid?
|
8
|
+
ISNI.valid? @number
|
9
|
+
end
|
10
|
+
|
11
|
+
# output a hyphenated version of this ISNI
|
12
|
+
def to_s
|
13
|
+
if valid?
|
14
|
+
[
|
15
|
+
@number[0,4],
|
16
|
+
@number[4,4],
|
17
|
+
@number[8,4],
|
18
|
+
@number[12,4],
|
19
|
+
].join("-")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.valid?(isni)
|
24
|
+
isni = isni.to_s.gsub(/[^\dxX]/, "")
|
25
|
+
isni.length == 16 && isni == ISNI.complete(isni[0,15])
|
26
|
+
end
|
27
|
+
|
28
|
+
# Purely for generating new ISNI numbers
|
29
|
+
#
|
30
|
+
def self.complete(num)
|
31
|
+
num = num.to_s.gsub(/[^\dxX]/, "")
|
32
|
+
return nil unless num.length == 15 && num.match(/\A\d+\Z/)
|
33
|
+
|
34
|
+
sum = num.chars.map(&:to_i).inject(0) do |accum,i|
|
35
|
+
if accum == 0
|
36
|
+
accum = i * 2
|
37
|
+
else
|
38
|
+
accum = (accum + i) * 2
|
39
|
+
end
|
40
|
+
end
|
41
|
+
remainder = 12 - (sum % 11) % 11
|
42
|
+
if remainder == 10
|
43
|
+
check = "X"
|
44
|
+
else
|
45
|
+
check = remainder
|
46
|
+
end
|
47
|
+
|
48
|
+
"#{num}#{check}"
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: isni
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Healy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ir_b
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: a (very) small library for working with ISNI and ORCID
|
56
|
+
email:
|
57
|
+
- james@yob.id.au
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- CHANGELOG
|
63
|
+
- MIT-LICENSE
|
64
|
+
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- lib/isni.rb
|
67
|
+
homepage: http://github.com/yob/isni
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- "--title"
|
74
|
+
- ISNI
|
75
|
+
- "--line-numbers"
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.2.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: a (very) small library for working with ISNI and ORCID
|
94
|
+
test_files: []
|
95
|
+
has_rdoc: true
|