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

- old
+ new

@@ -1,9 +1,10 @@ # frozen_string_literal: true require 'xml/mapping_extensions' require 'datacite/mapping/name_identifier' +require 'datacite/mapping/contributor_name' module Datacite module Mapping # Controlled vocabulary of contributor types. @@ -91,31 +92,56 @@ self.identifier = identifier self.affiliations = affiliations || [] self.type = type end + # name can be entered as a string or a ContributorName object, but it will be stored + # internally as a ContributorName object def name=(value) - new_value = value&.strip - raise ArgumentError, 'Name cannot be empty or nil' unless new_value && !new_value.empty? - @name = new_value + raise ArgumentError, 'Name cannot be empty or nil' unless value + + @contributor_name = if value.is_a?(ContributorName) + value + else + ContributorName.new(value: value) + end end + def contributor_name=(value) + raise ArgumentError, 'ContributorName cannot be empty or nil' unless value + + @contributor_name = value + end + + def name + @contributor_name&.value + end + def type=(value) raise ArgumentError, 'Type cannot be nil' unless value + @type = value end # @!attribute [rw] name - # @return [String] the personal name of the contributor, in the format `Family, Given`. Cannot be empty or nil - text_node :name, 'contributorName' + # @return [String] The personal name of the creator, in the format `Family, Given`. Cannot be empty or nil. + object_node :contributor_name, 'contributorName', class: ContributorName + # @!attribute [rw] given_name + # @return [String, nil] The given name of the creator. Optional. + text_node :given_name, 'givenName', default_value: nil + + # @!attribute [rw] family_name + # @return [String, nil] The family name of the creator. Optional. + text_node :family_name, 'familyName', default_value: nil + # @!attribute [rw] identifier # @return [NameIdentifier, nil] an identifier for the contributor. Optional. object_node :identifier, 'nameIdentifier', class: NameIdentifier, default_value: nil # @!attribute [rw] affiliations # @return [Array<String>] the contributor's affiliations. Defaults to an empty list. - array_node :affiliations, 'affiliation', class: String, default_value: [] + array_node :affiliations, 'affiliation', class: Affiliation, default_value: [] # @!attribute [rw] type # @return [ContributorType] the contributor type. Cannot be nil. typesafe_enum_node :type, '@contributorType', class: ContributorType