Class: DigitalObjectIdentifier
- Inherits:
-
Object
- Object
- DigitalObjectIdentifier
- Defined in:
- app/models/digital_object_identifier.rb
Instance Attribute Summary collapse
-
#accepted_date ⇒ Object
Returns the value of attribute accepted_date.
-
#contributor ⇒ Object
Returns the value of attribute contributor.
-
#created_date ⇒ Object
Returns the value of attribute created_date.
-
#creator ⇒ Object
Returns the value of attribute creator.
-
#data_size ⇒ Object
Returns the value of attribute data_size.
-
#description ⇒ Object
Returns the value of attribute description.
-
#format ⇒ Object
Returns the value of attribute format.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#name_id ⇒ Object
Returns the value of attribute name_id.
-
#publicationyear ⇒ Object
Returns the value of attribute publicationyear.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#resource_type ⇒ Object
Returns the value of attribute resource_type.
-
#rights ⇒ Object
Returns the value of attribute rights.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#target ⇒ Object
Returns the value of attribute target.
-
#title ⇒ Object
Returns the value of attribute title.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#create_doi ⇒ Object
Step - 1: Create DOI by passing 5 metadata - target, creator, title, publisher, publicationyear.
-
#create_xml ⇒ Object
This method creates XML data which is used for extra metadata other than the 5 metadata which was used in Step - 1.
-
#data ⇒ Object
Mandatory fields for creating DOI.
-
#doi ⇒ Object
Create DOI or return if already created.
-
#sanitize_data ⇒ Object
This method replaces special characters like %, :, n and r in the XML data and appends to the basic metadata which was used while creating DOI in Step - 1.
-
#update_doi ⇒ Object
Step - 2: Update the DOI metadata with more attributes.
Instance Attribute Details
#accepted_date ⇒ Object
Returns the value of attribute accepted_date.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def accepted_date @accepted_date end |
#contributor ⇒ Object
Returns the value of attribute contributor.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def contributor @contributor end |
#created_date ⇒ Object
Returns the value of attribute created_date.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def created_date @created_date end |
#creator ⇒ Object
Returns the value of attribute creator.
3 4 5 |
# File 'app/models/digital_object_identifier.rb', line 3 def creator @creator end |
#data_size ⇒ Object
Returns the value of attribute data_size.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def data_size @data_size end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def description @description end |
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def format @format end |
#lang ⇒ Object
Returns the value of attribute lang.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def lang @lang end |
#name_id ⇒ Object
Returns the value of attribute name_id.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def name_id @name_id end |
#publicationyear ⇒ Object
Returns the value of attribute publicationyear.
3 4 5 |
# File 'app/models/digital_object_identifier.rb', line 3 def publicationyear @publicationyear end |
#publisher ⇒ Object
Returns the value of attribute publisher.
3 4 5 |
# File 'app/models/digital_object_identifier.rb', line 3 def publisher @publisher end |
#resource_type ⇒ Object
Returns the value of attribute resource_type.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def resource_type @resource_type end |
#rights ⇒ Object
Returns the value of attribute rights.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def rights @rights end |
#subject ⇒ Object
Returns the value of attribute subject.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def subject @subject end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def subtitle @subtitle end |
#target ⇒ Object
Returns the value of attribute target.
3 4 5 |
# File 'app/models/digital_object_identifier.rb', line 3 def target @target end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'app/models/digital_object_identifier.rb', line 3 def title @title end |
#version ⇒ Object
Returns the value of attribute version.
4 5 6 |
# File 'app/models/digital_object_identifier.rb', line 4 def version @version end |
Instance Method Details
#create_doi ⇒ Object
Step - 1: Create DOI by passing 5 metadata - target, creator, title, publisher, publicationyear
12 13 14 15 |
# File 'app/models/digital_object_identifier.rb', line 12 def create_doi response = RestClient.post DoiConfig.url_for_creating_doi, data, :content_type => 'text/plain' return response end |
#create_xml ⇒ Object
This method creates XML data which is used for extra metadata other than the 5 metadata which was used in Step - 1.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/digital_object_identifier.rb', line 38 def create_xml builder = Nokogiri::XML::Builder.new do |xml| xml.resource("xmlns" => "http://datacite.org/schema/kernel-2.2", "xmlns:xsi" =>"http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "http://datacite.org/schema/kernel-2.2 http://schema.datacite.org/meta/kernel-2.2/metadata.xsd") { xml.identifier(:identifierType => "DOI"){ xml.text doi.sub("doi:", "") } xml.creators{ xml.creator{ xml.creatorName creator xml.nameIdentifier(:nameIdentifierScheme => "ISNI") { xml.text name_id } } } xml.titles{ xml.title title xml.title(:titleType => "Subtitle") { xml.text subtitle} } xml.publisher publisher xml.publicationYear publicationyear xml.subjects{ xml.subject subject } xml.contributors{ xml.contributor(:contributorType => "DataManager"){ xml.contributorName contributor } } xml.dates{ xml.date(:dateType => "Valid"){ xml.text created_date } xml.date(:dateType => "Accepted"){ xml.text accepted_date } } xml.language lang xml.resourceType(:resourceTypeGeneral => "Image"){ xml.text resource_type } xml.sizes{ xml.size data_size } xml.formats{ xml.format format } xml.version version xml.rights rights xml.descriptions{ xml.description(:descriptionType => "Other") { xml.text description } } } end end |
#data ⇒ Object
Mandatory fields for creating DOI.
7 8 9 |
# File 'app/models/digital_object_identifier.rb', line 7 def data "_target: #{target}\ndatacite.creator: #{creator}\ndatacite.title: #{title}\ndatacite.publisher: #{publisher}\ndatacite.publicationyear: #{publicationyear}\n" end |
#doi ⇒ Object
Create DOI or return if already created.
18 19 20 21 22 23 24 |
# File 'app/models/digital_object_identifier.rb', line 18 def doi @doi ||= create_doi if @doi.include?("success") @doi = @doi.split("|")[0].sub("success:", "").strip end @doi end |
#sanitize_data ⇒ Object
This method replaces special characters like %, :, n and r in the XML data and appends to the basic metadata which was used while creating DOI in Step - 1.
33 34 35 |
# File 'app/models/digital_object_identifier.rb', line 33 def sanitize_data data + "datacite: #{create_xml.to_xml.gsub("%", "%25").gsub(":", "%3A").gsub("\n", "%0D%0A").gsub("\r", "")}\n" end |
#update_doi ⇒ Object
Step - 2: Update the DOI metadata with more attributes. The extra metadata will need to be in the xml format.
27 28 29 30 |
# File 'app/models/digital_object_identifier.rb', line 27 def update_doi response = RestClient.post "#{DoiConfig.url_for_updating_doi}#{doi}", sanitize_data, :content_type => 'text/plain; charset=UTF-8', :content_length => sanitize_data.size, :accept => 'text/plain' return response end |