Class: PDCMetadata::Resource
- Inherits:
-
Object
- Object
- PDCMetadata::Resource
- Defined in:
- app/models/pdc_metadata/resource.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#ark ⇒ Object
Returns the value of attribute ark.
-
#collection_tags ⇒ Object
Returns the value of attribute collection_tags.
-
#communities ⇒ Object
Returns the value of attribute communities.
-
#creators ⇒ Object
Returns the value of attribute creators.
-
#description ⇒ Object
Returns the value of attribute description.
-
#doi ⇒ Object
Returns the value of attribute doi.
-
#domains ⇒ Object
Returns the value of attribute domains.
-
#funders ⇒ Object
Returns the value of attribute funders.
-
#keywords ⇒ Object
Returns the value of attribute keywords.
-
#migrated ⇒ Object
Returns the value of attribute migrated.
-
#organizational_contributors ⇒ Object
Returns the value of attribute organizational_contributors.
-
#publication_year ⇒ Object
Returns the value of attribute publication_year.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#related_objects ⇒ Object
Returns the value of attribute related_objects.
-
#resource_type ⇒ Object
Returns the value of attribute resource_type.
-
#resource_type_general ⇒ Object
Returns the value of attribute resource_type_general.
-
#rights_many ⇒ Object
Returns the value of attribute rights_many.
-
#subcommunities ⇒ Object
Returns the value of attribute subcommunities.
-
#titles ⇒ Object
Returns the value of attribute titles.
-
#version_number ⇒ Object
Returns the value of attribute version_number.
Class Method Summary collapse
- .default_resource_type_general ⇒ Object
-
.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.
- .resource_type_general_values ⇒ Object
Instance Method Summary collapse
-
#accessors ⇒ Object
rubocop:enable Metrics/MethodLength.
- #datacite_serialization ⇒ Object
- #identifier ⇒ Object
- #identifier_type ⇒ Object
- #individual_contributors ⇒ Object
- #individual_contributors=(value) ⇒ Object
-
#initialize(doi: nil, title: nil, resource_type: nil, resource_type_general: nil, creators: [], description: nil) ⇒ Resource
constructor
rubocop:disable Metrics/MethodLength.
- #main_title ⇒ Object
- #other_titles ⇒ Object
- #to_xml ⇒ Object
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
#ark ⇒ Object
Returns the value of attribute ark.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def ark @ark end |
#collection_tags ⇒ Object
Returns the value of attribute collection_tags.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def @collection_tags end |
#communities ⇒ Object
Returns the value of attribute communities.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def communities @communities end |
#creators ⇒ Object
Returns the value of attribute creators.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def creators @creators end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def description @description end |
#doi ⇒ Object
Returns the value of attribute doi.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def doi @doi end |
#domains ⇒ Object
Returns the value of attribute domains.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def domains @domains end |
#funders ⇒ Object
Returns the value of attribute funders.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def funders @funders end |
#keywords ⇒ Object
Returns the value of attribute keywords.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def keywords @keywords end |
#migrated ⇒ Object
Returns the value of attribute migrated.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def migrated @migrated end |
#organizational_contributors ⇒ Object
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_year ⇒ Object
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 |
#publisher ⇒ Object
Returns the value of attribute publisher.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def publisher @publisher end |
#related_objects ⇒ Object
Returns the value of attribute related_objects.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def @related_objects end |
#resource_type ⇒ Object
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_general ⇒ Object
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_many ⇒ Object
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 |
#subcommunities ⇒ Object
Returns the value of attribute subcommunities.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def subcommunities @subcommunities end |
#titles ⇒ Object
Returns the value of attribute titles.
12 13 14 |
# File 'app/models/pdc_metadata/resource.rb', line 12 def titles @titles end |
#version_number ⇒ Object
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_general ⇒ Object
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) (resource, jsonb_hash) set_funders(resource, jsonb_hash) resource end |
.resource_type_general_values ⇒ Object
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
#accessors ⇒ Object
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_serialization ⇒ Object
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 |
#identifier ⇒ Object
56 57 58 |
# File 'app/models/pdc_metadata/resource.rb', line 56 def identifier @doi end |
#identifier_type ⇒ Object
60 61 62 63 |
# File 'app/models/pdc_metadata/resource.rb', line 60 def identifier_type return nil if @doi.nil? "DOI" end |
#individual_contributors ⇒ Object
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_title ⇒ Object
65 66 67 |
# File 'app/models/pdc_metadata/resource.rb', line 65 def main_title @titles.find(&:main?)&.title end |
#other_titles ⇒ Object
69 70 71 |
# File 'app/models/pdc_metadata/resource.rb', line 69 def other_titles @titles.select { |title| title.main? == false } end |
#to_xml ⇒ Object
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 |