rof 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 455635fe2cf09958271943bca2e7aa9b5a48a709
4
- data.tar.gz: f315979e84b760ff2537033bd661cfa03f0a44a6
3
+ metadata.gz: a758b08f2917578d0af74b15925348e59f4f1be8
4
+ data.tar.gz: 66fc12edffcf6716c188186efaae4b6a27c8d7ca
5
5
  SHA512:
6
- metadata.gz: 53ffaf40c93225551091e2a3357e9343a4b0c0dbe3b4f6bff508496fd4006cbd3cc79bbf3d985d49cfe6445860b119eee65caa082ae9400010748e7d70089a5c
7
- data.tar.gz: 032d767da4543330d695c3dfb8bca7259ea998559db9e9a78e8cf31cdbf27bcf01863c842535488f548204b4c2519a283a97f8cff70de7fb4e0b6a5fcc737e75
6
+ metadata.gz: f42308bf063ae22ec22ddbdc19d06bddb56c741e158834e4a4e7b3f82e49389f455c629e57d7a28014ba1617d0e707883ec8086dc7f518cfdb3f027ad3013eed
7
+ data.tar.gz: 30d352eaf0860643ebe35ef40a45721dccee826dedad9c6c8a5de01e240eab48404d63d24330692523dfd72845f72fe3056d7a65766ed67b2a6455530a975f7e
@@ -22,15 +22,16 @@ module ROF
22
22
  # @return [Hash]
23
23
  def to_rof
24
24
  rof = @rof.deep_dup
25
- expand_blank_node_locations(rof)
26
- append_properties_to(rof)
25
+ expand_blank_node_locations!(rof)
26
+ rof = append_properties_to(rof)
27
+ rof = force_cardinality_for_backwards_compatability(rof)
27
28
  rof
28
29
  end
29
30
 
30
31
  private
31
32
 
32
33
  # The antics of the blank node! See the specs for blank nodes to see the expected behavior.
33
- def expand_blank_node_locations(rof)
34
+ def expand_blank_node_locations!(rof)
34
35
  @blank_node_locations.each_pair do |node, locations|
35
36
  locations.each_pair do |location, key_value_pairs|
36
37
  data = rof
@@ -70,6 +71,19 @@ module ROF
70
71
  rof
71
72
  end
72
73
 
74
+ class TooManyEmbargoDatesError < RuntimeError
75
+ end
76
+
77
+ def force_cardinality_for_backwards_compatability(rof)
78
+ rights = rof.fetch('rights', {})
79
+ if rights.key?('embargo-date')
80
+ embargo_dates = Array.wrap(rights['embargo-date'])
81
+ raise TooManyEmbargoDatesError if embargo_dates.size > 1
82
+ rof['rights']['embargo-date'] = embargo_dates.first
83
+ end
84
+ rof
85
+ end
86
+
73
87
  public
74
88
 
75
89
  # @api public
@@ -1,3 +1,3 @@
1
1
  module ROF
2
- VERSION="1.2.4"
2
+ VERSION="1.2.5"
3
3
  end
@@ -81,6 +81,7 @@
81
81
  "@id": "_:b1"
82
82
  },
83
83
  "nd:accessEdit": "curate_batch_user",
84
+ "nd:accessEmbargoDate": "2016-11-16",
84
85
  "nd:accessRead": "wma1",
85
86
  "nd:accessReadGroup": "public",
86
87
  "nd:afmodel": "Etd",
@@ -115,6 +115,40 @@ module ROF
115
115
  end
116
116
  end
117
117
  end
118
+
119
+ describe '#to_rof' do
120
+ let(:initial_rof) do
121
+ {
122
+ "rights"=> {
123
+ "edit"=>["curate_batch_user"],
124
+ "embargo-date"=>["2016-11-16"],
125
+ "read"=>["wma1"],
126
+ "read-groups"=>["public"]
127
+ }
128
+ }
129
+ end
130
+ context 'with one embargo-date' do
131
+ it 'will have a single embargo date' do
132
+ rof = initial_rof
133
+ rof['rights']['embargo-date'] = ['2016-1-2']
134
+ expect(described_class.new(rof).to_rof['rights'].fetch('embargo-date')).to eq('2016-1-2')
135
+ end
136
+ end
137
+ context 'with more than one embargo-date' do
138
+ it 'will raise an exception' do
139
+ rof = initial_rof
140
+ rof['rights']['embargo-date'] = ['2016-1-2', '2016-2-3']
141
+ expect { described_class.new(rof).to_rof }.to raise_error(described_class::TooManyEmbargoDatesError)
142
+ end
143
+ end
144
+ context 'no embargo-date' do
145
+ it 'will not have an embargo-date' do
146
+ rof = initial_rof
147
+ rof['rights'].delete('embargo-date')
148
+ expect { described_class.new(rof).to_rof['rights'].fetch('embargo-date') }.to raise_error(KeyError)
149
+ end
150
+ end
151
+ end
118
152
  end
119
153
  end
120
154
  end
@@ -14,6 +14,7 @@ module ROF
14
14
  output = described_class.call(jsonld_from_curatend, {})
15
15
  expect(output.size).to eq(1) # We have one item
16
16
  expect(output.first.fetch('pid')).to eq('und:pr76f190f54')
17
+ expect(output.first['rights'].fetch('embargo-date')).to eq("2016-11-16")
17
18
  end
18
19
  end
19
20
  describe '.call' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen