class Datacite::Mapping::Resource
A collection of metadata properties chosen for the accurate and consistent identification of a resource for citation and retrieval purposes, along with recommended use instructions. The resource that is being identified can be of any kind, but it is typically a dataset.
Public Class Methods
Initialies a new {Resource}
@param identifier [Identifier] a persistent identifier that identifies a resource. @param creators [Array<Creator>] the main researchers involved working on the data, or the authors of the publication in priority order. @param titles [Array<Title>] the names or titles by which a resource is known. @param publisher [Publisher] the name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource. @param publication_year [Integer] year when the resource is made publicly available. @param subjects [Array<Subject>] subjects, keywords, classification codes, or key phrases describing the resource. @param funding_references [Array<FundingReference>] information about financial support (funding) for the resource being registered. @param contributors [Array<Contributor>] institutions or persons responsible for collecting, creating, or otherwise contributing to the developement of the dataset. @param dates [Array<Date>] different dates relevant to the work. @param language [String, nil] Primary language of the resource: an IETF BCP 47, ISO 639-1 language code. @param resource_type [ResourceType, nil] the type of the resource @param alternate_identifiers [Array<AlternateIdentifier>] an identifier or identifiers other than the primary {Identifier} applied to the resource being registered. @param related_identifiers [Array<RelatedIdentifier>] identifiers of related resources. @param sizes [Array<String>] unstructured size information about the resource. @param formats [Array<String>] technical format of the resource, e.g. file extension or MIME type. @param version [String] version number of the resource. @param rights_list [Array<Rights>] rights information for this resource. @param descriptions [Array<Description>] all additional information that does not fit in any of the other categories. @param geo_locations [Array<GeoLocations>] spatial region or named place where the data was gathered or about which the data is focused.
# File lib/datacite/mapping/resource.rb, line 65 def initialize(identifier:, creators:, titles:, publisher:, publication_year:, subjects: [], contributors: [], dates: [], language: nil, funding_references: [], resource_type: nil, alternate_identifiers: [], related_identifiers: [], sizes: [], formats: [], version: nil, rights_list: [], descriptions: [], geo_locations: []) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize self.identifier = identifier self.creators = creators self.titles = titles self.publisher = publisher self.publication_year = publication_year self.subjects = subjects self.funding_references = funding_references self.contributors = contributors self.dates = dates self.language = language self.resource_type = resource_type self.alternate_identifiers = alternate_identifiers self.related_identifiers = related_identifiers self.sizes = sizes self.formats = formats self.version = version self.rights_list = rights_list self.descriptions = descriptions self.geo_locations = geo_locations end
Public Instance Methods
# File lib/datacite/mapping/resource.rb, line 147 def alternate_identifiers=(value) @alternate_identifiers = value || [] end
# File lib/datacite/mapping/resource.rb, line 135 def contributors=(value) @contributors = value || [] end
Convenience method to get the creators' affiliations. (Bear in mind that each creator can have multiple affiliations.) @return [Array[Array]] An array containing each creator's array of affiliations.
# File lib/datacite/mapping/resource.rb, line 269 def creator_affiliations creators.map(&:affiliation_names) end
Convenience method to get the creators' names. @return [[Array] An array of the creators' names.
# File lib/datacite/mapping/resource.rb, line 262 def creator_names creators.map { |c| c&.creator_name&.value } end
# File lib/datacite/mapping/resource.rb, line 101 def creators=(value) raise ArgumentError, 'Resource must have at least one creator' unless value && !value.empty? @creators = value end
# File lib/datacite/mapping/resource.rb, line 139 def dates=(value) @dates = value || [] end
# File lib/datacite/mapping/resource.rb, line 172 def descriptions=(value) @descriptions = (value&.select(&:value)) || [] end
Overrides Namespaced::InstanceMethods.fill_into_xml to check mapping
# File lib/datacite/mapping/resource.rb, line 32 def fill_into_xml(xml, options = { mapping: :_default }) current_namespace = namespace return super if options[:mapping] != :datacite_3 || current_namespace.uri == DATACITE_3_NAMESPACE.uri begin @namespace = DATACITE_3_NAMESPACE.with_prefix(current_namespace.prefix) super ensure @namespace = current_namespace end end
# File lib/datacite/mapping/resource.rb, line 159 def formats=(value) @formats = value || [] end
Convenience method to get the funding contributor. @return [Contributor, nil] the contributor of type FUNDER, if any.
# File lib/datacite/mapping/resource.rb, line 275 def funder_contrib contributors.find { |c| c.type == ContributorType::FUNDER } end
Convenience method to get the funding contributor identifier. @return [NameIdentifier, nil] the identifier of the funding contributor, if any.
# File lib/datacite/mapping/resource.rb, line 288 def funder_id funder_contrib&.identifier end
Convenience method to get the funding contributor identifier as a string. @return [String, nil] the string value of the funding contributor's identifier, if any.
# File lib/datacite/mapping/resource.rb, line 294 def funder_id_value funder_id&.value end
Convenience method to get the name of the funding contributor. @deprecated contributor type 'funder' is deprecated. Use {FundingReference} instead. @return [String, nil] the name of the funding contributor, if any.
# File lib/datacite/mapping/resource.rb, line 282 def funder_name funder_contrib&.name end
# File lib/datacite/mapping/resource.rb, line 143 def funding_references=(value) @funding_references = value || [] end
# File lib/datacite/mapping/resource.rb, line 176 def geo_locations=(value) @geo_locations = (value&.select(&:location?)) || [] end
# File lib/datacite/mapping/resource.rb, line 95 def identifier=(value) raise ArgumentError, 'Resource must have an identifier' unless value @identifier = value end
Shadows Namespaced::ClassMethods.namespace
# File lib/datacite/mapping/resource.rb, line 27 def namespace @namespace ||= DATACITE_4_NAMESPACE end
Sets the namespace prefix to be used when writing out XML
(defaults to nil) @param prefix [String, nil] The new prefix, or nil to use the default,
unprefixed namespace
# File lib/datacite/mapping/resource.rb, line 90 def namespace_prefix=(prefix) old_namespace = namespace @namespace = ::XML::MappingExtensions::Namespace.new(uri: old_namespace.uri, schema_location: old_namespace.schema_location, prefix: prefix) end
# File lib/datacite/mapping/resource.rb, line 125 def publication_year=(value) raise ArgumentError, 'Resource must have a four-digit publication year' unless value&.to_i&.between?(1000, 9999) @publication_year = value.to_i end
publisher can be entered as a string or a Publisher
object, but it will be stored as a Publisher
object
# File lib/datacite/mapping/resource.rb, line 115 def publisher=(value) raise ArgumentError, 'Publisher must have a value' unless value @publisher = if value.is_a?(Publisher) value else Publisher.new(value: value) end end
# File lib/datacite/mapping/resource.rb, line 168 def rights_list=(value) @rights_list = value || [] end
# File lib/datacite/mapping/resource.rb, line 155 def sizes=(value) @sizes = value || [] end
# File lib/datacite/mapping/resource.rb, line 131 def subjects=(value) @subjects = (value&.select(&:value)) || [] end
# File lib/datacite/mapping/resource.rb, line 107 def titles=(value) raise ArgumentError, 'Resource must have at least one title' unless value && !value.empty? @titles = value end
# File lib/datacite/mapping/resource.rb, line 163 def version=(value) new_value = value&.to_s @version = new_value&.strip end