identifiers 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +23 -1
- data/lib/identifiers.rb +1 -0
- data/lib/identifiers/orcid.rb +27 -0
- data/spec/identifiers/orcid_spec.rb +39 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19a6b42db016b656d1c1114ae8e0dee77c69f5e1
|
4
|
+
data.tar.gz: a954deca478c665226f8073cc9837a4c64ad2e88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22c9cc78407e5561a3122a766368278eb0258cc71d61e715411fd6c9a2224a573c5818d782fe2167d79b4aad367dfa310b062d497d5b529e4fd3bf801e4ffccd
|
7
|
+
data.tar.gz: 80b229ac1c454db783a6b200d2ca225c603aaa5d5adb9a5009b31752c7358f9442d164e430c2f400bdcdbaa8c79e60f1582ee4a95615b18110307814f751d0ec
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
All notable changes to this project will be documented in this file. This
|
3
3
|
project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [0.3.0] - 2016-11-03
|
6
|
+
### Added
|
7
|
+
- Support for ORCID
|
8
|
+
|
5
9
|
## [0.2.0] - 2016-11-01
|
6
10
|
### Changed
|
7
11
|
- Strip leading 0s from Pubmed IDs. 0 is no longer a valid Pubmed ID.
|
data/README.md
CHANGED
@@ -10,13 +10,14 @@ Collection of utilities related to the extraction, validation and normalization
|
|
10
10
|
- [PubMed](http://www.ncbi.nlm.nih.gov/pubmed)
|
11
11
|
- [RePEc](https://en.wikipedia.org/wiki/Research_Papers_in_Economics)
|
12
12
|
- [URN](https://en.wikipedia.org/wiki/Uniform_Resource_Name)
|
13
|
+
- [ORCID](http://orcid.org/)
|
13
14
|
|
14
15
|
## Installation
|
15
16
|
|
16
17
|
Add this line to your application's Gemfile:
|
17
18
|
|
18
19
|
```ruby
|
19
|
-
gem 'identifiers', '~> 0.
|
20
|
+
gem 'identifiers', '~> 0.3'
|
20
21
|
```
|
21
22
|
|
22
23
|
And then execute:
|
@@ -36,6 +37,27 @@ Identifiers::URN.new('urn:abc:123')
|
|
36
37
|
Identifiers::URN('urn:abc:123')
|
37
38
|
```
|
38
39
|
|
40
|
+
## By identifier
|
41
|
+
|
42
|
+
`.extract` is a common method that works across all the supported identifiers.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Identifiers::AdsBibcode.extract('')
|
46
|
+
Identifiers::ArxivId.extract('')
|
47
|
+
Identifiers::DOI.extract('')
|
48
|
+
Identifiers::Handle.extract('')
|
49
|
+
Identifiers::ISBN.extract('')
|
50
|
+
Identifiers::NationalClinicalTrialId.extract('')
|
51
|
+
Identifiers::ORCID.extract('')
|
52
|
+
Identifiers::PubmedId.extract('')
|
53
|
+
Identifiers::RepecId.extract('')
|
54
|
+
Identifiers::URN.extract('')
|
55
|
+
```
|
56
|
+
|
57
|
+
But for some identifiers might have more. Check their implementation to see all the methods available.
|
58
|
+
|
59
|
+
For `URN`s, please check the [URN gem documentation](https://github.com/altmetric/urn) to see all the available options.
|
60
|
+
|
39
61
|
## Contributing
|
40
62
|
|
41
63
|
Bug reports and pull requests are welcome on GitHub at https://github.com/altmetric/identifiers.
|
data/lib/identifiers.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Identifiers
|
2
|
+
class ORCID
|
3
|
+
REGEX = /\b(?:\d{4}-){3}\d{3}[\dx]\b/i
|
4
|
+
|
5
|
+
def self.extract(str)
|
6
|
+
str.scan(REGEX).select { |orcid| valid?(orcid) }.map(&:upcase)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.valid?(str)
|
10
|
+
digit = calculate_digit(str)
|
11
|
+
return false unless digit
|
12
|
+
|
13
|
+
digit == str[-1].upcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.calculate_digit(str)
|
17
|
+
return unless str =~ REGEX
|
18
|
+
|
19
|
+
base_digits = str.chop.tr('-', '')
|
20
|
+
total = 0
|
21
|
+
base_digits.each_char { |c| total = (total + Integer(c)) * 2 }
|
22
|
+
remainder = total % 11
|
23
|
+
result = (12 - remainder) % 11
|
24
|
+
result == 10 ? 'X' : result.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'identifiers/orcid'
|
2
|
+
|
3
|
+
RSpec.describe Identifiers::ORCID do
|
4
|
+
describe '.extract' do
|
5
|
+
it 'extracts ORCIDs from a string' do
|
6
|
+
str = "orcid.org/0000-0002-0088-0058\n0000-0002-0488-8591"
|
7
|
+
|
8
|
+
expect(described_class.extract(str)).to contain_exactly('0000-0002-0088-0058', '0000-0002-0488-8591')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'normalizes the ORCID extracted' do
|
12
|
+
str = 'orcid.org/0000-0003-0166-248x'
|
13
|
+
|
14
|
+
expect(described_class.extract(str)).to contain_exactly('0000-0003-0166-248X')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.valid?' do
|
19
|
+
it 'returns true if the ORCID is valid' do
|
20
|
+
str = '0000-0002-0088-0058'
|
21
|
+
|
22
|
+
expect(described_class.valid?(str)).to eq(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns false if the ORCID is not valid' do
|
26
|
+
str = '0000-0002-0088-005X'
|
27
|
+
|
28
|
+
expect(described_class.valid?(str)).to eq(false)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.calculate_digit' do
|
33
|
+
it 'calculates the digit of an ORCID' do
|
34
|
+
str = '0000-0002-0088-0058'
|
35
|
+
|
36
|
+
expect(described_class.calculate_digit(str)).to eq('8')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: identifiers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Hernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: urn
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/identifiers/handle.rb
|
84
84
|
- lib/identifiers/isbn.rb
|
85
85
|
- lib/identifiers/national_clinical_trial_id.rb
|
86
|
+
- lib/identifiers/orcid.rb
|
86
87
|
- lib/identifiers/pubmed_id.rb
|
87
88
|
- lib/identifiers/repec_id.rb
|
88
89
|
- lib/identifiers/urn.rb
|
@@ -92,6 +93,7 @@ files:
|
|
92
93
|
- spec/identifiers/handle_spec.rb
|
93
94
|
- spec/identifiers/isbn_spec.rb
|
94
95
|
- spec/identifiers/national_clinical_trial_id_spec.rb
|
96
|
+
- spec/identifiers/orcid_spec.rb
|
95
97
|
- spec/identifiers/pubmed_id_spec.rb
|
96
98
|
- spec/identifiers/repec_id_spec.rb
|
97
99
|
- spec/identifiers/urn_spec.rb
|
@@ -127,6 +129,7 @@ test_files:
|
|
127
129
|
- spec/identifiers/handle_spec.rb
|
128
130
|
- spec/identifiers/isbn_spec.rb
|
129
131
|
- spec/identifiers/national_clinical_trial_id_spec.rb
|
132
|
+
- spec/identifiers/orcid_spec.rb
|
130
133
|
- spec/identifiers/pubmed_id_spec.rb
|
131
134
|
- spec/identifiers/repec_id_spec.rb
|
132
135
|
- spec/identifiers/urn_spec.rb
|