Class: PDCMetadata::Resource

Inherits:
Object
  • Object
show all
Defined in:
app/models/pdc_metadata/resource.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doi: nil, title: nil, resource_type: nil, resource_type_general: nil, creators: [], description: nil) ⇒ Resource

rubocop:disable Metrics/MethodLength



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/pdc_metadata/resource.rb', line 17

def initialize(doi: nil, title: nil, resource_type: nil, resource_type_general: nil, creators: [], description: nil)
  @titles = []
  @titles << PDCMetadata::Title.new(title:) unless title.nil?
  @description = description
  @collection_tags = []
  @creators = creators
  @resource_type = resource_type || "Dataset"
  @resource_type_general = resource_type_general || self.class.default_resource_type_general
  @publisher = "Princeton University"
  @publication_year = Time.zone.today.year
  @ark = nil
  @doi = doi
  @rights_many = []
  @version_number = "1"
  @related_objects = []
  @keywords = []
  @contributors = []
  @organizational_contributors = []
  @funders = []
  @domains = []
  @communities = []
  @subcommunities = []
  @migrated = false
end

Instance Attribute Details

#arkObject

Returns the value of attribute ark.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def ark
  @ark
end

#collection_tagsObject

Returns the value of attribute collection_tags.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def collection_tags
  @collection_tags
end

#communitiesObject

Returns the value of attribute communities.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def communities
  @communities
end

#creatorsObject

Returns the value of attribute creators.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def creators
  @creators
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def description
  @description
end

#doiObject

Returns the value of attribute doi.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def doi
  @doi
end

#domainsObject

Returns the value of attribute domains.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def domains
  @domains
end

#fundersObject

Returns the value of attribute funders.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def funders
  @funders
end

#keywordsObject

Returns the value of attribute keywords.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def keywords
  @keywords
end

#migratedObject

Returns the value of attribute migrated.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def migrated
  @migrated
end

#organizational_contributorsObject

Returns the value of attribute organizational_contributors.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def organizational_contributors
  @organizational_contributors
end

#publication_yearObject

Returns the value of attribute publication_year.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def publication_year
  @publication_year
end

#publisherObject

Returns the value of attribute publisher.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def publisher
  @publisher
end

Returns the value of attribute related_objects.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def related_objects
  @related_objects
end

#resource_typeObject

Returns the value of attribute resource_type.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def resource_type
  @resource_type
end

#resource_type_generalObject

Returns the value of attribute resource_type_general.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def resource_type_general
  @resource_type_general
end

#rights_manyObject

Returns the value of attribute rights_many.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def rights_many
  @rights_many
end

#subcommunitiesObject

Returns the value of attribute subcommunities.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def subcommunities
  @subcommunities
end

#titlesObject

Returns the value of attribute titles.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def titles
  @titles
end

#version_numberObject

Returns the value of attribute version_number.



12
13
14
# File 'app/models/pdc_metadata/resource.rb', line 12

def version_number
  @version_number
end

Class Method Details

.default_resource_type_generalObject



107
108
109
# File 'app/models/pdc_metadata/resource.rb', line 107

def default_resource_type_general
  "Dataset"
end

.new_from_jsonb(jsonb_hash) ⇒ Object

Creates a PDCMetadata::Resource from a JSONB postgres field

This jsonb_hash can be created by running JSON.parse(pdc_metadata_resource.to_json)
 or by loading it from the work.metadata jsonb field


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/pdc_metadata/resource.rb', line 87

def new_from_jsonb(jsonb_hash)
  resource = PDCMetadata::Resource.new
  return resource if jsonb_hash.blank?
  set_basics(resource, jsonb_hash)
  (resource, jsonb_hash)
  (resource, jsonb_hash)
  set_titles(resource, jsonb_hash)
  set_creators(resource, jsonb_hash)
  set_individual_contributors(resource, jsonb_hash)
  set_organizational_contributors(resource, jsonb_hash)
  set_related_objects(resource, jsonb_hash)
  set_funders(resource, jsonb_hash)

  resource
end

.resource_type_general_valuesObject



103
104
105
# File 'app/models/pdc_metadata/resource.rb', line 103

def resource_type_general_values
  Datacite::Mapping::ResourceTypeGeneral.map(&:value)
end

Instance Method Details

#accessorsObject

rubocop:enable Metrics/MethodLength



43
44
45
46
# File 'app/models/pdc_metadata/resource.rb', line 43

def accessors
  setters = methods.map(&:to_s).filter { |s| s.match?(/\w=$/) }
  setters.map { |s| s.delete("=").to_sym }
end

#datacite_serializationObject



79
80
81
# File 'app/models/pdc_metadata/resource.rb', line 79

def datacite_serialization
  @datacite_serialization ||= PDCSerialization::Datacite.new_from_work_resource(self)
end

#identifierObject



56
57
58
# File 'app/models/pdc_metadata/resource.rb', line 56

def identifier
  @doi
end

#identifier_typeObject



60
61
62
63
# File 'app/models/pdc_metadata/resource.rb', line 60

def identifier_type
  return nil if @doi.nil?
  "DOI"
end

#individual_contributorsObject



48
49
50
# File 'app/models/pdc_metadata/resource.rb', line 48

def individual_contributors
  @contributors
end

#individual_contributors=(value) ⇒ Object



52
53
54
# File 'app/models/pdc_metadata/resource.rb', line 52

def individual_contributors=(value)
  @contributors = value
end

#main_titleObject



65
66
67
# File 'app/models/pdc_metadata/resource.rb', line 65

def main_title
  @titles.find(&:main?)&.title
end

#other_titlesObject



69
70
71
# File 'app/models/pdc_metadata/resource.rb', line 69

def other_titles
  @titles.select { |title| title.main? == false }
end

#to_xmlObject



73
74
75
76
77
# File 'app/models/pdc_metadata/resource.rb', line 73

def to_xml
  xml_declaration = '<?xml version="1.0"?>'
  xml_body = datacite_serialization.to_xml
  xml_declaration + "\n" + xml_body + "\n"
end