lib/datacite/mapping/related_identifier.rb in datacite-mapping-0.3.0 vs lib/datacite/mapping/related_identifier.rb in datacite-mapping-0.4.0

- old
+ new

@@ -1,8 +1,9 @@ # frozen_string_literal: true require 'xml/mapping_extensions' +require 'datacite/mapping/resource_type' module Datacite module Mapping # Controlled list of relationships of the {Resource} to a related resource. @@ -35,10 +36,16 @@ new :IS_NEW_VERSION_OF, 'IsNewVersionOf' # @!parse IS_PREVIOUS_VERSION_OF = IsPreviousVersionOf new :IS_PREVIOUS_VERSION_OF, 'IsPreviousVersionOf' + # @!parse HAS_VERSION = HasVersion + new :HAS_VERSION, 'HasVersion' + + # @!parse IS_VERSION_OF = IsVersionOf + new :IS_VERSION_OF, 'IsVersionOf' + # @!parse IS_PART_OF = IsPartOf new :IS_PART_OF, 'IsPartOf' # @!parse HAS_PART = HasPart new :HAS_PART, 'HasPart' @@ -80,10 +87,28 @@ new :IS_DERIVED_FROM, 'IsDerivedFrom' # @!parse IS_SOURCE_OF = IsSourceOf new :IS_SOURCE_OF, 'IsSourceOf' + # @!parse IS_OBSOLETED_BY = IsObsoletedBy + new :IS_OBSOLETED_BY, 'IsObsoletedBy' + + # @!parse OBSOLETES = Obsoletes + new :OBSOLETES, 'Obsoletes' + + # @!parse IS_DESCRIBED_BY = IsDescribedBy + new :IS_DESCRIBED_BY, 'IsDescribedBy' + + # @!parse DESCRIBES = Describes + new :DESCRIBES, 'Describes' + + # @!parse IS_REQUIRED_BY = IsRequiredBy + new :IS_REQUIRED_BY, 'IsRequiredBy' + + # @!parse REQUIRES = Requires + new :REQUIRES, 'Requires' + end # Controlled list of related identifier types. class RelatedIdentifierType < TypesafeEnum::Base # @!parse ARK = ARK @@ -137,23 +162,28 @@ # @!parse URN = URN new :URN, 'URN' # @!parse IGSN = IGSN new :IGSN, 'IGSN' + + # @!parse W3ID = w3id + new :W3ID, 'w3id' end class Datacite3RidTypeNode < XML::MappingExtensions::TypesafeEnumNode def to_xml_text(enum_instance) return super unless enum_instance == RelatedIdentifierType::IGSN + super(RelatedIdentifierType::HANDLE) end end XML::Mapping.add_node_class(Datacite3RidTypeNode) class Datacite3RidValueNode < XML::Mapping::TextNode def obj_to_xml(obj, xml) return super unless obj.identifier_type == RelatedIdentifierType::IGSN + igsn_value = obj.value handle_value = "10273/#{igsn_value}" # TODO: move this somewhere more general ReadOnlyNodes.warn("IGSN identifiers not directly supported in Datacite 3; converting IGSN #{igsn_value} to Handle #{handle_value}") set_attr_value(xml, handle_value) @@ -171,31 +201,34 @@ # @param value [String] the identifier value. Cannot be nil. # @param identifier_type [RelatedIdentifierType] the type of the related identifier. Cannot be nil. # @param related_metadata_scheme [String, nil] the name of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional. # @param scheme_uri [URI, nil] the URI of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional. # @param scheme_type [String, nil] the type of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional. - def initialize(relation_type:, value:, identifier_type:, related_metadata_scheme: nil, scheme_uri: nil, scheme_type: nil) # rubocop:disable Metrics/ParameterLists + def initialize(relation_type:, value:, identifier_type:, related_metadata_scheme: nil, scheme_uri: nil, scheme_type: nil) self.relation_type = relation_type self.value = value self.identifier_type = identifier_type self.related_metadata_scheme = related_metadata_scheme self.scheme_uri = scheme_uri self.scheme_type = scheme_type end def value=(value) raise ArgumentError, 'Value cannot be empty or nil' unless value && !value.empty? + @value = value end def identifier_type=(value) raise ArgumentError, 'Identifier type cannot be empty or nil' unless value + @identifier_type = value end def relation_type=(value) raise ArgumentError, 'Relation type cannot be nil' unless value + @relation_type = value end root_element_name 'relatedIdentifier' @@ -212,9 +245,13 @@ typesafe_enum_node :identifier_type, '@relatedIdentifierType', class: RelatedIdentifierType # @!attribute [rw] related_metadata_scheme # @return [String, nil] the name of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional. text_node :related_metadata_scheme, '@relatedMetadataScheme', default_value: nil + + # @!attribute [rw] resource_type_general + # @return [ResourceTypeGeneral] the general resource type + typesafe_enum_node :resource_type_general, '@resourceTypeGeneral', class: ResourceTypeGeneral, default_value: nil # @!attribute [rw] scheme_uri # @return [URI, nil] the URI of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional. uri_node :scheme_uri, '@schemeURI', default_value: nil