Class: Identifiers::DOI
- Inherits:
-
Object
- Object
- Identifiers::DOI
- Defined in:
- lib/identifiers/doi.rb
Constant Summary collapse
- PATTERN =
%r{ \b 10 # Directory indicator (always 10) \. (?: # ISBN-A 97[89]\. # ISBN (GS1) Bookland prefix \d{2,8} # ISBN registration group element and publisher prefix / # Prefix/suffix divider \d{1,7} # ISBN title enumerator and check digit | # DOI \d{4,9} # Registrant code / # Prefix/suffix divider \S+ # DOI suffix ) }x
- VALID_ENDING =
/ (?: \p{^Punct} # Non-punctuation character | \(.+\) # Balanced parentheses | 2-\# # Early Wiley DOI suffix ) \z /x
Class Method Summary collapse
Class Method Details
.extract(str) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/identifiers/doi.rb', line 31 def self.extract(str) str .to_s .downcase .scan(PATTERN) .map { |doi| strip_punctuation(doi) } .compact end |
.extract_one(str) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/identifiers/doi.rb', line 40 def self.extract_one(str) match = str.to_s.downcase[PATTERN] return unless match strip_punctuation(match) end |
.strip_punctuation(doi) ⇒ Object
47 48 49 50 51 |
# File 'lib/identifiers/doi.rb', line 47 def self.strip_punctuation(doi) return doi if doi =~ VALID_ENDING extract_one(doi.sub(/\p{Punct}\z/, '')) end |