Class: Datacite::Mapping::Identifier
- Inherits:
-
Object
- Object
- Datacite::Mapping::Identifier
- Includes:
- XML::Mapping
- Defined in:
- lib/datacite/mapping/identifier.rb
Overview
The persistent identifier that identifies the resource.
Constant Summary collapse
- DOI =
'DOI'
Instance Attribute Summary collapse
-
#identifier_type
Gets the identifiery type.
-
#value ⇒ String
The identifier value.
Class Method Summary collapse
-
.from_doi(doi_string)
Converts a string DOI value to an
Identifier
.
Instance Method Summary collapse
-
#initialize(value:) ⇒ Identifier
constructor
Initializes a new Identifier.
Constructor Details
#initialize(value:) ⇒ Identifier
Initializes a new Datacite::Mapping::Identifier
24 25 26 27 |
# File 'lib/datacite/mapping/identifier.rb', line 24 def initialize(value:) self.identifier_type = DOI self.value = value end |
Instance Attribute Details
#identifier_type
Gets the identifiery type.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/datacite/mapping/identifier.rb', line 16 class Identifier include XML::Mapping DOI = 'DOI' # Initializes a new {Identifier} # @param value [String] # the identifier value. Must be a valid DOI value (`10.`_registrant code_`/`_suffix_) def initialize(value:) self.identifier_type = DOI self.value = value end 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 # Sets the identifier type. Should only be called by the XML mapping engine. # @param new_value [String] # the identifier type (always 'DOI') def identifier_type=(new_value) raise ArgumentError, "Identifier type '#{new_value}' must be 'DOI'" unless DOI == new_value @identifier_type = new_value end # Gets the identifiery type. def identifier_type @identifier_type ||= DOI end # Converts a string DOI value to an `Identifier`. # @param doi_string [String] 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 text_node :value, 'text()' text_node :identifier_type, '@identifierType' fallback_mapping :datacite_3, :_default end |
#value ⇒ String
Returns the identifier value. Must be a valid DOI value (10.
registrant code/
suffix).
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/datacite/mapping/identifier.rb', line 16 class Identifier include XML::Mapping DOI = 'DOI' # Initializes a new {Identifier} # @param value [String] # the identifier value. Must be a valid DOI value (`10.`_registrant code_`/`_suffix_) def initialize(value:) self.identifier_type = DOI self.value = value end 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 # Sets the identifier type. Should only be called by the XML mapping engine. # @param new_value [String] # the identifier type (always 'DOI') def identifier_type=(new_value) raise ArgumentError, "Identifier type '#{new_value}' must be 'DOI'" unless DOI == new_value @identifier_type = new_value end # Gets the identifiery type. def identifier_type @identifier_type ||= DOI end # Converts a string DOI value to an `Identifier`. # @param doi_string [String] 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 text_node :value, 'text()' text_node :identifier_type, '@identifierType' fallback_mapping :datacite_3, :_default end |
Class Method Details
.from_doi(doi_string)
Converts a string DOI value to an Identifier
.
53 54 55 56 57 58 |
# 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 |