Class: Datacite::Mapping::DataciteXMLFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/datacite/mapping/datacite_xml_factory.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doi_value:, se_resource_id:, total_size_bytes:, version:) ⇒ DataciteXMLFactory

Returns a new instance of DataciteXMLFactory.



11
12
13
14
15
16
# File 'lib/datacite/mapping/datacite_xml_factory.rb', line 11

def initialize(doi_value:, se_resource_id:, total_size_bytes:, version:)
  @doi_value = doi_value
  @se_resource_id = se_resource_id
  @total_size_bytes = total_size_bytes
  @version = version && version.to_s
end

Instance Attribute Details

#doi_valueObject (readonly)

Returns the value of attribute doi_value.



6
7
8
# File 'lib/datacite/mapping/datacite_xml_factory.rb', line 6

def doi_value
  @doi_value
end

#se_resource_idObject (readonly)

Returns the value of attribute se_resource_id.



7
8
9
# File 'lib/datacite/mapping/datacite_xml_factory.rb', line 7

def se_resource_id
  @se_resource_id
end

#total_size_bytesObject (readonly)

Returns the value of attribute total_size_bytes.



8
9
10
# File 'lib/datacite/mapping/datacite_xml_factory.rb', line 8

def total_size_bytes
  @total_size_bytes
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/datacite/mapping/datacite_xml_factory.rb', line 9

def version
  @version
end

Instance Method Details

#build_datacite_xml(datacite_3: false) ⇒ Object



18
19
20
21
22
23
# File 'lib/datacite/mapping/datacite_xml_factory.rb', line 18

def build_datacite_xml(datacite_3: false)
  dcs_resource = build_resource(datacite_3: datacite_3)

  return dcs_resource.write_xml(mapping: :datacite_3) if datacite_3
  dcs_resource.write_xml
end

#build_resource(datacite_3: false) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



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
# File 'lib/datacite/mapping/datacite_xml_factory.rb', line 25

def build_resource(datacite_3: false) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  pub_year = se_resource.publication_years[0] # TODO: make this has_one instead of has_many

  dcs_resource = Resource.new(
    identifier: Identifier.from_doi(doi_value),
    creators: se_resource.creators.map do |c|
      Creator.new(
        name: c.creator_full_name,
        identifier: to_dcs_identifier(c.name_identifier),
        affiliations: c.affiliations.map(&:smart_name)
      )
    end,
    titles: se_resource.titles.map { |t| Title.new(value: t.title, type: t.title_type_mapping_obj) },
    publisher: to_dcs_publisher(se_resource.publisher),
    publication_year: to_dcs_pub_year(pub_year)
  )

  dcs_resource.language = 'en'
  dcs_resource.resource_type = to_dcs_type(se_resource.resource_type)
  dcs_resource.sizes = ["#{total_size_bytes} bytes"]
  dcs_resource.formats = se_resource.formats.map(&:format)
  dcs_resource.version = version

  add_subjects(dcs_resource)
  add_contributors(dcs_resource)
  add_dates(dcs_resource)
  add_alt_ids(dcs_resource)
  add_related_ids(dcs_resource)
  add_rights(dcs_resource)
  add_descriptions(dcs_resource)
  add_locations(dcs_resource)
  add_funding(dcs_resource, datacite_3: datacite_3)

  dcs_resource
end