Class: Datacite::Mapping::Resource

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Includes:
XML::MappingExtensions::Namespaced
Defined in:
lib/datacite/mapping/resource.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#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: []) ⇒ Resource

Initialies a new Datacite::Mapping::Resource

Parameters:

  • identifier (Identifier)

    a persistent identifier that identifies a resource.

  • creators (Array<Creator>)

    the main researchers involved working on the data, or the authors of the publication in priority order.

  • titles (Array<Title>)

    the names or titles by which a resource is known.

  • publisher (String)

    the name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource.

  • publication_year (Integer)

    year when the resource is made publicly available.

  • subjects (Array<Subject>) (defaults to: [])

    subjects, keywords, classification codes, or key phrases describing the resource.

  • funding_references (Array<FundingReference>) (defaults to: [])

    information about financial support (funding) for the resource being registered.

  • contributors (Array<Contributor>) (defaults to: [])

    institutions or persons responsible for collecting, creating, or otherwise contributing to the developement of the dataset.

  • dates (Array<Date>) (defaults to: [])

    different dates relevant to the work.

  • language (String, nil) (defaults to: nil)

    Primary language of the resource: an IETF BCP 47, ISO 639-1 language code.

  • resource_type (ResourceType, nil) (defaults to: nil)

    the type of the resource

  • alternate_identifiers (Array<AlternateIdentifier>) (defaults to: [])

    an identifier or identifiers other than the primary Identifier applied to the resource being registered.

  • related_identifiers (Array<RelatedIdentifier>) (defaults to: [])

    identifiers of related resources.

  • sizes (Array<String>) (defaults to: [])

    unstructured size information about the resource.

  • formats (Array<String>) (defaults to: [])

    technical format of the resource, e.g. file extension or MIME type.

  • version (String) (defaults to: nil)

    version number of the resource.

  • rights_list (Array<Rights>) (defaults to: [])

    rights information for this resource.

  • descriptions (Array<Description>) (defaults to: [])

    all additional information that does not fit in any of the other categories.

  • geo_locations (Array<GeoLocations>) (defaults to: [])

    spatial region or named place where the data was gathered or about which the data is focused.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/datacite/mapping/resource.rb', line 60

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/ParameterLists, 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

Instance Attribute Details

#alternate_identifiersArray<AlternateIdentifier>

Returns an identifier or identifiers other than the primary Identifier applied to the resource being registered.

Returns:



211
# File 'lib/datacite/mapping/resource.rb', line 211

array_node :alternate_identifiers, 'alternateIdentifiers', 'alternateIdentifier', class: AlternateIdentifier, default_value: []

#contributorsArray<Contributor>

Returns institutions or persons responsible for collecting, creating, or otherwise contributing to the developement of the dataset.

Returns:

  • (Array<Contributor>)

    institutions or persons responsible for collecting, creating, or otherwise contributing to the developement of the dataset.



195
# File 'lib/datacite/mapping/resource.rb', line 195

array_node :contributors, 'contributors', 'contributor', class: Contributor, default_value: []

#creatorsArray<Creator>

Returns the main researchers involved working on the data, or the authors of the publication in priority order.

Returns:

  • (Array<Creator>)

    the main researchers involved working on the data, or the authors of the publication in priority order.



171
# File 'lib/datacite/mapping/resource.rb', line 171

array_node :creators, 'creators', 'creator', class: Creator

#datesArray<Date>

Returns different dates relevant to the work.

Returns:

  • (Array<Date>)

    different dates relevant to the work.



199
# File 'lib/datacite/mapping/resource.rb', line 199

array_node :dates, 'dates', 'date', class: Date, default_value: []

#descriptionsArray<Description>

Returns all additional information that does not fit in any of the other categories.

Returns:

  • (Array<Description>)

    all additional information that does not fit in any of the other categories.



235
# File 'lib/datacite/mapping/resource.rb', line 235

array_node :descriptions, 'descriptions', 'description', class: Description, default_value: []

#formatsArray<String>

Returns technical format of the resource, e.g. file extension or MIME type.

Returns:

  • (Array<String>)

    technical format of the resource, e.g. file extension or MIME type.



223
# File 'lib/datacite/mapping/resource.rb', line 223

array_node :formats, 'formats', 'format', class: String, default_value: []

#fundingReferencesArray<FundingReference>

Returns information about financial support (funding) for the resource being registered.

Returns:

  • (Array<FundingReference>)

    information about financial support (funding) for the resource being registered.



191
# File 'lib/datacite/mapping/resource.rb', line 191

array_node :funding_references, 'fundingReferences', 'fundingReference', class: FundingReference, default_value: []

#geo_locationsArray<GeoLocations>

Returns spatial region or named place where the data was gathered or about which the data is focused.

Returns:

  • (Array<GeoLocations>)

    spatial region or named place where the data was gathered or about which the data is focused.



239
# File 'lib/datacite/mapping/resource.rb', line 239

array_node :geo_locations, 'geoLocations', 'geoLocation', class: GeoLocation, default_value: []

#identifierIdentifier

Returns a persistent identifier that identifies a resource.

Returns:

  • (Identifier)

    a persistent identifier that identifies a resource.



167
# File 'lib/datacite/mapping/resource.rb', line 167

identifier_node :identifier, 'identifier', class: Identifier

#languageString

Returns Primary language of the resource: an IETF BCP 47, ISO 639-1 language code.

Returns:

  • (String)

    Primary language of the resource: an IETF BCP 47, ISO 639-1 language code.



203
# File 'lib/datacite/mapping/resource.rb', line 203

text_node :language, 'language', default_value: nil

#publication_yearInteger

Returns year when the resource is made publicly available.

Returns:

  • (Integer)

    year when the resource is made publicly available.



183
# File 'lib/datacite/mapping/resource.rb', line 183

numeric_node :publication_year, 'publicationYear'

#publisherString

Returns the name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource.

Returns:

  • (String)

    the name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource.



179
# File 'lib/datacite/mapping/resource.rb', line 179

text_node :publisher, 'publisher'

Returns identifiers of related resources.

Returns:



215
# File 'lib/datacite/mapping/resource.rb', line 215

array_node :related_identifiers, 'relatedIdentifiers', 'relatedIdentifier', class: RelatedIdentifier, default_value: []

#resource_typeResourceType?

Returns the type of the resource. Optional.

Returns:

  • (ResourceType, nil)

    the type of the resource. Optional.



207
# File 'lib/datacite/mapping/resource.rb', line 207

object_node :resource_type, 'resourceType', class: ResourceType, default_value: nil

#rights_listArray<Rights>

Returns rights information for this resource.

Returns:

  • (Array<Rights>)

    rights information for this resource.



231
# File 'lib/datacite/mapping/resource.rb', line 231

array_node :rights_list, 'rightsList', 'rights', class: Rights, default_value: []

#sizesArray<String>

Returns unstructured size information about the resource.

Returns:

  • (Array<String>)

    unstructured size information about the resource.



219
# File 'lib/datacite/mapping/resource.rb', line 219

array_node :sizes, 'sizes', 'size', class: String, default_value: []

#subjectsArray<Subject>

Returns subjects, keywords, classification codes, or key phrases describing the resource.

Returns:

  • (Array<Subject>)

    subjects, keywords, classification codes, or key phrases describing the resource.



187
# File 'lib/datacite/mapping/resource.rb', line 187

array_node :subjects, 'subjects', 'subject', class: Subject, default_value: []

#titlesArray<Title>

Returns the names or titles by which a resource is known.

Returns:

  • (Array<Title>)

    the names or titles by which a resource is known.



175
# File 'lib/datacite/mapping/resource.rb', line 175

array_node :titles, 'titles', 'title', class: Title

#versionString

Returns version number of the resource. Optional.

Returns:

  • (String)

    version number of the resource. Optional.



227
# File 'lib/datacite/mapping/resource.rb', line 227

text_node :version, 'version', default_value: nil

Instance Method Details

#creator_affiliationsArray[Array[String]]

Convenience method to get the creators' affiliations. (Bear in mind that each creator can have multiple affiliations.)

Returns:

  • (Array[Array[String]])

    An array containing each creator's array of affiliations.



250
251
252
# File 'lib/datacite/mapping/resource.rb', line 250

def creator_affiliations
  creators.map(&:affiliations)
end

#creator_names[Array[String]] An array of the creators' names.

Convenience method to get the creators' names.

Returns:

  • ([Array[String]] An array of the creators' names.)

    [Array[String]] An array of the creators' names.



243
244
245
# File 'lib/datacite/mapping/resource.rb', line 243

def creator_names
  creators.map(&:name)
end

#fill_into_xml(xml, options = { mapping: :_default })

Overrides Namespaced::InstanceMethods.fill_into_xml to check mapping



30
31
32
33
34
35
36
37
# File 'lib/datacite/mapping/resource.rb', line 30

def fill_into_xml(xml, options = { mapping: :_default })
  if options[:mapping] == :datacite_3
    unless namespace.uri == DATACITE_3_NAMESPACE.uri
      @namespace = DATACITE_3_NAMESPACE.with_prefix(namespace.prefix)
    end
  end
  super
end

#funder_contribContributor?

Convenience method to get the funding contributor.

Returns:

  • (Contributor, nil)

    the contributor of type FUNDER, if any.



256
257
258
# File 'lib/datacite/mapping/resource.rb', line 256

def funder_contrib
  contributors.find { |c| c.type == ContributorType::FUNDER }
end

#funder_idNameIdentifier?

Convenience method to get the funding contributor identifier.

Returns:

  • (NameIdentifier, nil)

    the identifier of the funding contributor, if any.



269
270
271
# File 'lib/datacite/mapping/resource.rb', line 269

def funder_id
  funder_contrib.identifier if funder_contrib
end

#funder_id_valueString?

Convenience method to get the funding contributor identifier as a string.

Returns:

  • (String, nil)

    the string value of the funding contributor's identifier, if any.



275
276
277
# File 'lib/datacite/mapping/resource.rb', line 275

def funder_id_value
  funder_id.value if funder_id
end

#funder_nameString?

Deprecated.

contributor type 'funder' is deprecated. Use FundingReference instead.

Convenience method to get the name of the funding contributor.

Returns:

  • (String, nil)

    the name of the funding contributor, if any.



263
264
265
# File 'lib/datacite/mapping/resource.rb', line 263

def funder_name
  funder_contrib.name if funder_contrib
end

#funding_references=(value)



128
129
130
# File 'lib/datacite/mapping/resource.rb', line 128

def funding_references=(value)
  @funding_references = value || []
end

#namespace

Shadows Namespaced::ClassMethods.namespace



25
26
27
# File 'lib/datacite/mapping/resource.rb', line 25

def namespace
  @namespace ||= DATACITE_4_NAMESPACE
end

#namespace_prefix=(prefix)

Sets the namespace prefix to be used when writing out XML (defaults to nil)

Parameters:

  • prefix (String, nil)

    The new prefix, or nil to use the default, unprefixed namespace



85
86
87
88
# File 'lib/datacite/mapping/resource.rb', line 85

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