class Datacite::Mapping::Identifier

The persistent identifier that identifies the resource.

@!attribute [r] identifier_type

@return [String] the identifier type (always 'DOI')

@!attribute [rw] value

@return [String] the identifier value. Must be a valid DOI value (`10.`_registrant code_`/`_suffix_)

Constants

DOI

Public Class Methods

from_doi(doi_string) click to toggle source

Converts a string DOI value to an ‘Identifier`. @param doi_string [String]

# File lib/datacite/mapping/identifier.rb, line 53
def self.from_doi(doi_string)
  match = doi_string.match(DOI_PATTERN)
  raise ArgumentError, "'#{doi_string}' does not appear to contain a valid DOI" unless match

  Identifier.new(value: match[0])
end
new(value:) click to toggle source

Initializes a new {Identifier} @param value [String]

the identifier value. Must be a valid DOI value (`10.`_registrant code_`/`_suffix_)
# File lib/datacite/mapping/identifier.rb, line 24
def initialize(value:)
  self.identifier_type = DOI
  self.value = value
end

Public Instance Methods

identifier_type() click to toggle source

Gets the identifiery type.

# File lib/datacite/mapping/identifier.rb, line 47
def identifier_type
  @identifier_type ||= DOI
end
identifier_type=(new_value) click to toggle source

Sets the identifier type. Should only be called by the XML mapping engine. @param new_value [String]

the identifier type (always 'DOI')
# File lib/datacite/mapping/identifier.rb, line 40
def identifier_type=(new_value)
  raise ArgumentError, "Identifier type '#{new_value}' must be 'DOI'" unless DOI == new_value

  @identifier_type = new_value
end
value=(new_value) click to toggle source
# File lib/datacite/mapping/identifier.rb, line 29
def value=(new_value)
  new_value = new_value&.strip
  raise ArgumentError, 'Identifier must have a non-nil value' unless new_value
  raise ArgumentError, "Identifier value '#{new_value}' is not a valid DOI" unless new_value.match?(DOI_PATTERN)

  @value = new_value
end