class Stash::Merritt::SubmissionPackage::MerrittOAIDCBuilder
Constants
- DC_RELATION_TYPES
- ROOT_ATTRIBUTES
Attributes
resource_id[R]
Public Class Methods
new(resource_id:)
click to toggle source
Calls superclass method
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 25 def initialize(resource_id:) super(file_name: 'mrt-oaidc.xml') @resource_id = resource_id end
Public Instance Methods
contents()
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 30 def contents # rubocop:disable Metrics/MethodLength Nokogiri::XML::Builder.new do |xml| xml.qualifieddc(ROOT_ATTRIBUTES) do add_creators(xml) add_contributors(xml) add_title(xml) add_publisher(xml) add_pub_year(xml) add_subjects(xml) add_resource_type(xml) add_rights(xml) add_descriptions(xml) add_related_identifiers(xml) end end.to_xml.to_s end
Private Instance Methods
add_contributors(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 74 def add_contributors(xml) # Funder contributors are handled under 'add_descriptions' below resource.contributors.where.not(contributor_type: 'funder').each do |c| if (contrib_name = c.contributor_name) && !contrib_name.blank? xml.send(:'dc:contributor', contrib_name.strip) end end end
add_creators(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 57 def add_creators(xml) resource.authors.each { |c| xml.send(:'dc:creator', c.author_full_name.delete("\r").to_s) } end
add_descriptions(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 99 def add_descriptions(xml) strip_desc_linefeeds(xml) resource.contributors.where(contributor_type: 'funder').each do |c| xml.send(:'dc:description', to_dc_description(c)) end end
add_pub_year(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 61 def add_pub_year(xml) pub_year = resource.publication_years.first xml.send(:'dc:date', pub_year.publication_year) if pub_year end
add_publisher(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 66 def add_publisher(xml) xml.send(:'dc:publisher', (tenant.short_name || tenant.long_name || 'unknown').to_s) end
add_resource_type(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 87 def add_resource_type(xml) resource_type = (rt = resource.resource_type) && rt.resource_type_general xml.send(:'dc:type', resource_type.strip) unless resource_type.blank? end
add_rights(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 92 def add_rights(xml) resource.rights.each do |r| xml.send(:'dc:rights', r.rights.to_s) xml.send(:'dcterms:license', r.rights_uri.to_s, 'xsi:type' => 'dcterms:URI') end end
add_subjects(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 83 def add_subjects(xml) resource.subjects.each { |s| xml.send(:'dc:subject', s.subject.delete("\r").to_s) } end
add_title(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 70 def add_title(xml) xml.send(:'dc:title', resource.titles.where(title_type: nil).first.title.to_s) end
resource()
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 49 def resource @resource ||= StashEngine::Resource.find(resource_id) end
strip_desc_linefeeds(xml)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 114 def strip_desc_linefeeds(xml) resource.descriptions.each do |d| desc_text = d.description.to_s.delete("\r") xml.send(:'dc:description', desc_text.to_s) unless desc_text.blank? end end
tenant()
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 53 def tenant resource.tenant end
to_dc_description(contributor)
click to toggle source
# File lib/stash/merritt/submission_package/merritt_oaidc_builder.rb, line 106 def to_dc_description(contributor) contrib_name = contributor.contributor_name award_num = contributor.award_number desc_text = 'Data were created' desc_text << " with funding from #{contrib_name}" unless contrib_name.blank? desc_text << " under grant(s) #{award_num}" unless award_num.blank? end