datacite-mapping 0.1.17.1 → 0.1.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 398b5a165b8e4c39af2c0e7b18939bacbc6da51d
4
- data.tar.gz: e3d8833bff3e5cc8b2ec11e7120d3660fe3bead8
3
+ metadata.gz: 206495b36be88be8111bbb81c4634ea5e558134e
4
+ data.tar.gz: 87f325106c27c2c500e97885ff5422c445ec806f
5
5
  SHA512:
6
- metadata.gz: d248552035446c7c80dd7704246e3203d0e92ff90f4322280b7f6309ecd0b572527eeadd96deb3aa81dee7f6a9c87c8be30beab639359462b8197e12b922b88d
7
- data.tar.gz: f0431676af52cc968d6f3f22d5dd7332dccb563aa7ab71fab6c16ae6d9dd414eb825aebaf8b8bf27943f22b15e72b8c4ddbb6b514a71d931c5d83ec7523ef869
6
+ metadata.gz: 646bbce9bea6dd89c1a8608ce1647cc9727ba022dca531d6f11b2478707813afec72b7c6681fcb5ea784bb02409f4caff55aa4c0911e3776b848cf696038bf82
7
+ data.tar.gz: d522fcb20188b4d41f0fb076120a00741926987ac1142703a3f1592b98693e058ea6f06438ead7f84e2b89e369760e6bff8725aeda14247206d59d6e67e10291
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.17.2 (19 August 2016)
2
+
3
+ - Filter out `<subject/>` tags without values
4
+
1
5
  ## 0.1.17.1 (5 August 2016)
2
6
 
3
7
  - In `Rights::CC_BY`, use "Creative Commons Attribution 4.0 International (CC BY 4.0)"
@@ -4,7 +4,7 @@ module Datacite
4
4
  NAME = 'datacite-mapping'
5
5
 
6
6
  # The version of this gem
7
- VERSION = '0.1.17.1'
7
+ VERSION = '0.1.17.2'
8
8
 
9
9
  # The copyright notice for this gem
10
10
  COPYRIGHT = 'Copyright (c) 2016 The Regents of the University of California'
@@ -9,7 +9,7 @@ module Datacite
9
9
  # @!attribute [r] identifier_type
10
10
  # @return [String] the identifier type (always 'DOI')
11
11
  # @!attribute [rw] value
12
- # @return [String] the identifier value. Must be a valid DOI value (`10.`_registrant code_`/`_suffix_)
12
+ # @return [String, nil] the identifier value. Should be a valid DOI value (`10.`_registrant code_`/`_suffix_)
13
13
  class Identifier
14
14
  include XML::Mapping
15
15
 
@@ -23,8 +23,8 @@ module Datacite
23
23
  fallback_mapping(:_default, :nonvalidating)
24
24
 
25
25
  # Initializes a new {Identifier}
26
- # @param value [String]
27
- # the identifier value. Must be a valid DOI value (`10.`_registrant code_`/`_suffix_)
26
+ # @param value [String, nil]
27
+ # the identifier value. Should be a valid DOI value (`10.`_registrant code_`/`_suffix_)
28
28
  def initialize(value:)
29
29
  self.identifier_type = DOI
30
30
  self.value = value
@@ -20,7 +20,7 @@ module Datacite
20
20
  # A collection of metadata properties chosen for the accurate and consistent identification
21
21
  # of a resource for citation and retrieval purposes, along with recommended use instructions.
22
22
  # The resource that is being identified can be of any kind, but it is typically a dataset.
23
- class Resource
23
+ class Resource # rubocop:disable Metrics/ClassLength
24
24
  include XML::MappingExtensions::Namespaced
25
25
 
26
26
  namespace DATACITE_3_NAMESPACE
@@ -110,10 +110,14 @@ module Datacite
110
110
  @publication_year = value.to_i
111
111
  end
112
112
 
113
- def subject
113
+ def subjects
114
114
  (@subjects ||= []).select(&:value)
115
115
  end
116
116
 
117
+ def subjects=(value)
118
+ @subjects = (value || []).select(&:value)
119
+ end
120
+
117
121
  # @!attribute [rw] identifier
118
122
  # @return [Identifier] a persistent identifier that identifies a resource.
119
123
  object_node :identifier, 'identifier', class: Identifier
@@ -2,6 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  module Datacite
4
4
  module Mapping
5
+
6
+ describe FunderIdentifier do
7
+ describe '#new' do
8
+ it 'requires a non-nil type' do
9
+ expect do
10
+ FunderIdentifier.new(type: nil, value: 'http://doi.org/10.13039/501100000780')
11
+ end.to raise_error(ArgumentError)
12
+ end
13
+
14
+ it 'requires a non-nil value' do
15
+ expect do
16
+ FunderIdentifier.new(type: FunderIdentifierType::CROSSREF_FUNDER_ID, value: nil)
17
+ end.to raise_error(ArgumentError)
18
+ end
19
+ end
20
+ end
21
+
5
22
  describe FundingReference do
6
23
 
7
24
  describe '#initialize' do
@@ -11,6 +11,10 @@ module Datacite
11
11
  expect(id.value).to eq(value)
12
12
  end
13
13
 
14
+ it 'requires a non-nil value' do
15
+ expect { Identifier.new(value: nil) }.to raise_error(ArgumentError)
16
+ end
17
+
14
18
  it 'sets the type' do
15
19
  id = Identifier.new(value: '10.14749/1407399495')
16
20
  expect(id.identifier_type).to eq('DOI')
@@ -4,6 +4,20 @@ module Datacite
4
4
  module Mapping
5
5
  module Nonvalidating
6
6
  describe Identifier do
7
+
8
+ describe '#new' do
9
+ it 'accepts a nil value' do
10
+ id = Identifier.new(value: nil)
11
+ expect(id.identifier_type).to eq('DOI')
12
+ end
13
+
14
+ it 'accepts an invalid value' do
15
+ id = Identifier.new(value: 'elvis')
16
+ expect(id.value).to eq('elvis')
17
+ end
18
+
19
+ end
20
+
7
21
  describe '#load_from_xml' do
8
22
  it 'parses a valid identifier' do
9
23
  xml_text = "<identifier identifierType='DOI'>10.14749/1407399498</identifier>"
@@ -587,6 +587,60 @@ module Datacite
587
587
  describe 'subjects' do
588
588
  it 'returns the subject list'
589
589
  it 'returns an editable list'
590
+
591
+ describe 'nonvalidating mode' do
592
+ it 'filters out empty subjects' do
593
+ xml_text = "<resource xsi:schemaLocation='http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://datacite.org/schema/kernel-3'>
594
+ <identifier identifierType='DOI'>10.14749/1407399495</identifier>
595
+ <creators>
596
+ <creator>
597
+ <creatorName>Hedy Lamarr</creatorName>
598
+ </creator>
599
+ <creator>
600
+ <creatorName>Herschlag, Natalie</creatorName>
601
+ </creator>
602
+ </creators>
603
+ <titles>
604
+ <title>An Account of a Very Odd Monstrous Calf</title>
605
+ </titles>
606
+ <publisher>California Digital Library</publisher>
607
+ <publicationYear>2015</publicationYear>
608
+ <subjects>
609
+ <subject subjectScheme='LCSH' schemeURI='http://id.loc.gov/authorities/subjects' xml:lang='en-us'>Mammals--Embryology</subject>
610
+ <subject/>
611
+ <subject subjectScheme='dewey' schemeURI='http://dewey.info/' xml:lang='fr'>571.8 Croissance, développement, reproduction biologique (fécondation, sexualité)</subject>
612
+ <subject subjectScheme='dewey' schemeURI='http://dewey.info/'></subject>
613
+ </subjects>
614
+ <language>en</language>
615
+ </resource>"
616
+ resource = Resource.parse_xml(xml_text, mapping: :nonvalidating)
617
+
618
+ expected = [
619
+ Subject.new(
620
+ language: 'en-us',
621
+ scheme: 'LCSH',
622
+ scheme_uri: URI('http://id.loc.gov/authorities/subjects'),
623
+ value: 'Mammals--Embryology'
624
+ ),
625
+ Subject.new(
626
+ language: 'fr',
627
+ scheme: 'dewey',
628
+ scheme_uri: URI('http://dewey.info/'),
629
+ value: '571.8 Croissance, développement, reproduction biologique (fécondation, sexualité)'
630
+ )
631
+ ]
632
+
633
+ subjects = resource.subjects
634
+ expect(subjects.size).to eq(expected.size)
635
+ expected.each_with_index do |ex, i|
636
+ expect(subjects[i].language).to eq(ex.language)
637
+ expect(subjects[i].scheme).to eq(ex.scheme)
638
+ expect(subjects[i].scheme_uri).to eq(ex.scheme_uri)
639
+ expect(subjects[i].value).to eq(ex.value)
640
+ end
641
+ end
642
+ end
643
+
590
644
  end
591
645
 
592
646
  describe 'subjects=' do
@@ -745,6 +799,7 @@ module Datacite
745
799
  .gsub(Regexp.new('<subjects>\p{space}</subjects>', Regexp::MULTILINE), '')
746
800
  .gsub("'", '&apos;')
747
801
  .gsub('"', "'")
802
+ .gsub("<subject schemeURI='http://www.nlm.nih.gov/mesh/' subjectScheme='MeSH'/>", '')
748
803
 
749
804
  begin
750
805
  expect(actual_tidy).to be_xml(expected_tidy)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacite-mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17.1
4
+ version: 0.1.17.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-05 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typesafe_enum