libis-tools 0.9.15 → 0.9.16
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 +4 -4
- data/lib/libis/tools/config.rb +13 -9
- data/lib/libis/tools/metadata/dublin_core_record.rb +6 -3
- data/lib/libis/tools/mets_file.rb +31 -18
- data/lib/libis/tools/parameter.rb +18 -1
- data/lib/libis/tools/version.rb +1 -1
- data/lib/libis/tools/xml_document.rb +5 -6
- data/spec/metadata/dublin_core_spec.rb +6 -6
- data/spec/metadata/marc21_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0864d175751dfc12feb50a156f13200b12d14f52
|
4
|
+
data.tar.gz: 53c1f3a745b0f599e2d8c39ff6a57524c9cb7e91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d798591f94b555ac8ecdfede9a3a368b3bfeef313a06b3084e315cbcfc806ef1a3f324482d05d442f7f346a5d2a7815635bfff63e4b09e84f2041fa532a919ab
|
7
|
+
data.tar.gz: d87cd92dc1340e197da2527b4feb88d5e3b631afc76259a9031428affd7bf71a31e537eab7dfcd28cfcea7770b66f48c6f553c4d2894943e286680353a5852a9
|
data/lib/libis/tools/config.rb
CHANGED
@@ -25,7 +25,7 @@ module Libis
|
|
25
25
|
# p cfg[:my_text] # => 'abc'
|
26
26
|
# p cfg.logger.warn('message') # => W, [2015-03-16T12:51:01.180548 #28935] WARN -- : message
|
27
27
|
#
|
28
|
-
class Config
|
28
|
+
class Config
|
29
29
|
include Singleton
|
30
30
|
|
31
31
|
class << self
|
@@ -40,12 +40,18 @@ module Libis
|
|
40
40
|
|
41
41
|
end
|
42
42
|
|
43
|
+
def method_missing(name, *args, &block)
|
44
|
+
result = config.send(name, *args, &block)
|
45
|
+
self === config ? self : result
|
46
|
+
end
|
47
|
+
|
43
48
|
# Load configuration parameters from a YAML file or Hash.
|
44
49
|
#
|
45
50
|
# The file paths and Hashes are memorised and loaded again by the {#reload} methods.
|
46
51
|
# @param [String,Hash] file_or_hash
|
47
52
|
def <<(file_or_hash)
|
48
|
-
|
53
|
+
@config.send('<<', (file_or_hash)) { |data| @sources << data }
|
54
|
+
self
|
49
55
|
end
|
50
56
|
|
51
57
|
# Load all files and Hashes again.
|
@@ -59,15 +65,13 @@ module Libis
|
|
59
65
|
self
|
60
66
|
end
|
61
67
|
|
62
|
-
alias_method :deep_struct_clear!, :clear!
|
63
|
-
|
64
68
|
# Clear data and load all files and Hashes again.
|
65
69
|
#
|
66
70
|
# All configuration parameters are first deleted which means that any parameters
|
67
71
|
# added directly (not via file or hash) will no longer be available. Parameters set explicitly that also exist in
|
68
72
|
# the files or hashes will be reset to the values in those files and hashes.
|
69
73
|
def reload!
|
70
|
-
|
74
|
+
@config.clear!
|
71
75
|
reload
|
72
76
|
end
|
73
77
|
|
@@ -76,7 +80,7 @@ module Libis
|
|
76
80
|
# Not only all configuration parameters are deleted, but also the memorized list of loaded files
|
77
81
|
# and hashes are cleared and the logger configuration is reset to it's default status.
|
78
82
|
def clear!
|
79
|
-
|
83
|
+
@config.clear!
|
80
84
|
@sources = Array.new
|
81
85
|
@logger = ::Logger.new(STDOUT)
|
82
86
|
set_log_formatter
|
@@ -98,13 +102,13 @@ module Libis
|
|
98
102
|
end
|
99
103
|
end
|
100
104
|
|
101
|
-
attr_accessor :logger
|
105
|
+
attr_accessor :logger, :config, :sources
|
102
106
|
|
103
107
|
protected
|
104
108
|
|
105
109
|
def initialize(hash = nil, opts = {})
|
106
|
-
|
107
|
-
clear!
|
110
|
+
@config = ConfigFile.new(hash, opts)
|
111
|
+
self.clear!
|
108
112
|
end
|
109
113
|
|
110
114
|
end
|
@@ -68,19 +68,22 @@ module Libis
|
|
68
68
|
parent ||= root
|
69
69
|
m = /^([\/\.]*\/)?(dc(?:terms)?:)?(.*)/.match(tag.to_s)
|
70
70
|
return [] unless m[3]
|
71
|
-
path = (m[1] || '')
|
71
|
+
path = (m[1] || '')
|
72
|
+
ns, tag = get_namespace(tag)
|
73
|
+
path += "#{ns}:" if ns
|
74
|
+
path += tag
|
72
75
|
parent.xpath(path)
|
73
76
|
end
|
74
77
|
|
75
78
|
def get_namespace(tag)
|
76
79
|
m = /^((dc)?(terms)?(?:_|:)?)?([a-zA-Z_][-_.0-9a-zA-Z]+)(.*)/.match tag
|
77
|
-
ns = if m[1].
|
80
|
+
ns = if m[1].blank?
|
78
81
|
if DC_ELEMENTS.include?(m[4])
|
79
82
|
:dc
|
80
83
|
else
|
81
84
|
DCTERMS_ELEMENTS.include?(m[4]) ? :dcterms : nil
|
82
85
|
end
|
83
|
-
elsif m[3].
|
86
|
+
elsif m[3].blank?
|
84
87
|
:dc
|
85
88
|
else
|
86
89
|
:dcterms
|
@@ -14,7 +14,7 @@ module Libis
|
|
14
14
|
module IdContainer
|
15
15
|
|
16
16
|
def set_from_hash(h)
|
17
|
-
h.each { |k, v| send "#{k}=", v }
|
17
|
+
h.each { |k, v| send "#{k}=", v if respond_to?(k) }
|
18
18
|
end
|
19
19
|
|
20
20
|
def id
|
@@ -41,9 +41,10 @@ module Libis
|
|
41
41
|
class Representation
|
42
42
|
include IdContainer
|
43
43
|
|
44
|
-
attr_accessor :label, :preservation_type, :usage_type, :representation_code, :entity_type, :
|
44
|
+
attr_accessor :label, :preservation_type, :usage_type, :representation_code, :entity_type, :access_right_id,
|
45
|
+
:user_a, :user_b, :user_c,
|
46
|
+
:group_id, :priority, :order,
|
45
47
|
:digital_original, :content, :context, :hardware, :carrier, :original_name,
|
46
|
-
:user_a, :user_b, :user_c, :group_id,
|
47
48
|
:preservation_levels, :env_dependencies, :hardware_ids, :software_ids,
|
48
49
|
:hardware_infos, :software_infos, :relationship_infos, :environments,
|
49
50
|
:dc_record, :source_metadata
|
@@ -200,7 +201,7 @@ module Libis
|
|
200
201
|
# Rights section
|
201
202
|
rights_data = []
|
202
203
|
data = {
|
203
|
-
policyId:
|
204
|
+
policyId: access_right_id
|
204
205
|
}.cleanup
|
205
206
|
rights_data << Rights.new(data) unless data.empty?
|
206
207
|
dnx[:rights] = rights_data unless rights_data.empty?
|
@@ -218,20 +219,20 @@ module Libis
|
|
218
219
|
class File
|
219
220
|
include IdContainer
|
220
221
|
|
221
|
-
attr_accessor :label, :note, :location, :target_location, :mimetype, :entity_type,
|
222
|
+
attr_accessor :label, :note, :location, :target_location, :mimetype, :puid, :size, :entity_type,
|
222
223
|
:creation_date, :modification_date, :composition_level, :group_id,
|
224
|
+
:checksum_MD5, :checksum_SHA1, :checksum_SHA256,:checksum_SHA384,:checksum_SHA512,
|
223
225
|
:fixity_type, :fixity_value,
|
224
226
|
:preservation_levels, :inhibitors, :env_dependencies, :hardware_ids, :software_ids,
|
225
227
|
:signatures, :hardware_infos, :software_infos, :relationship_infos, :environments, :applications,
|
226
|
-
:dc_record, :source_metadata
|
227
|
-
:representation
|
228
|
+
:dc_record, :source_metadata, :representation
|
228
229
|
|
229
230
|
def xml_id
|
230
231
|
"fid#{id}"
|
231
232
|
end
|
232
233
|
|
233
|
-
def
|
234
|
-
"grp#{master.id rescue id}"
|
234
|
+
def make_group_id
|
235
|
+
"grp#{group_id || master.id rescue id}"
|
235
236
|
end
|
236
237
|
|
237
238
|
def master
|
@@ -285,18 +286,22 @@ module Libis
|
|
285
286
|
fileExtension: ::File.extname(orig_name),
|
286
287
|
fileMIMEType: mimetype,
|
287
288
|
fileSizeBytes: size,
|
288
|
-
|
289
|
+
formatLibraryId: puid
|
289
290
|
}.cleanup
|
290
291
|
tech_data << TechGeneralFile.new(data) unless data.empty?
|
291
292
|
# Fixity
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
293
|
+
%w'MD5 SHA1 SHA256 SHA384 SHA512'.each do |checksum_type|
|
294
|
+
if (checksum = self.send("checksum_#{checksum_type}"))
|
295
|
+
data = {
|
296
|
+
fixityType: checksum_type,
|
297
|
+
fixityValue: checksum,
|
298
|
+
}.cleanup
|
299
|
+
tech_data << TechFixity.new(data) unless data.empty?
|
300
|
+
end
|
301
|
+
end
|
297
302
|
# Object characteristics
|
298
303
|
data = {
|
299
|
-
groupID:
|
304
|
+
groupID: make_group_id
|
300
305
|
}.cleanup
|
301
306
|
tech_data << TechObjectChars.new(data) unless data.empty?
|
302
307
|
# Preservation level
|
@@ -554,6 +559,10 @@ module Libis
|
|
554
559
|
tag 'webHarvesting'
|
555
560
|
end
|
556
561
|
|
562
|
+
class CollectionInfo < DnxSection
|
563
|
+
tag 'Collection'
|
564
|
+
end
|
565
|
+
|
557
566
|
class PreservationLevel < DnxSection
|
558
567
|
tag 'preservationLevel'
|
559
568
|
end
|
@@ -740,6 +749,10 @@ module Libis
|
|
740
749
|
harvestTime: hash[:harvest_time],
|
741
750
|
}.cleanup
|
742
751
|
tech_data << WebHarvesting.new(data) unless data.empty?
|
752
|
+
data = {
|
753
|
+
collectionId: hash[:collection_id]
|
754
|
+
}.cleanup
|
755
|
+
tech_data << CollectionInfo.new(data) unless data.empty?
|
743
756
|
@dnx[:tech] = tech_data unless tech_data.empty?
|
744
757
|
data = {
|
745
758
|
policyId: hash[:access_right]
|
@@ -864,7 +877,7 @@ module Libis
|
|
864
877
|
ID: object.xml_id,
|
865
878
|
MIMETYPE: object.mimetype,
|
866
879
|
ADMID: amd_id(object.xml_id),
|
867
|
-
GROUPID: object.
|
880
|
+
GROUPID: object.make_group_id,
|
868
881
|
}.cleanup
|
869
882
|
h[:DMDID] = dmd_id(object.xml_id) if object.dc_record
|
870
883
|
|
@@ -891,7 +904,7 @@ module Libis
|
|
891
904
|
TYPE: 'PHYSICAL',
|
892
905
|
) {
|
893
906
|
xml[:mets].div(LABEL: map.representation.label) {
|
894
|
-
add_struct_map(xml, map.
|
907
|
+
add_struct_map(xml, map.div) if map.div
|
895
908
|
}
|
896
909
|
}
|
897
910
|
end
|
@@ -21,12 +21,24 @@ module Libis
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def dup
|
24
|
+
# noinspection RubySuperCallWithoutSuperclassInspection
|
24
25
|
new_obj = super
|
25
26
|
# noinspection RubyResolve
|
26
27
|
new_obj[:options] = Marshal.load(Marshal.dump(self[:options]))
|
27
28
|
new_obj
|
28
29
|
end
|
29
30
|
|
31
|
+
def merge!(other)
|
32
|
+
other.each do |k,v|
|
33
|
+
if k == :options
|
34
|
+
self[:options].merge!(v)
|
35
|
+
else
|
36
|
+
self[k] = v
|
37
|
+
end
|
38
|
+
end
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
30
42
|
def [](key)
|
31
43
|
# noinspection RubySuperCallWithoutSuperclassInspection
|
32
44
|
return super(key) if members.include?(key)
|
@@ -44,6 +56,7 @@ module Libis
|
|
44
56
|
end
|
45
57
|
|
46
58
|
def to_h
|
59
|
+
# noinspection RubySuperCallWithoutSuperclassInspection
|
47
60
|
super.inject({}) do |hash, key, value|
|
48
61
|
key == :options ? value.each { |k, v| hash[k] = v } : hash[key] = value
|
49
62
|
hash
|
@@ -159,7 +172,11 @@ module Libis
|
|
159
172
|
begin
|
160
173
|
self.superclass.parameter_defs.
|
161
174
|
each_with_object(@parameters) do |(name, param), hash|
|
162
|
-
hash
|
175
|
+
if hash.has_key?(name)
|
176
|
+
hash[name].merge!(param)
|
177
|
+
else
|
178
|
+
hash[name] = param.dup
|
179
|
+
end
|
163
180
|
end
|
164
181
|
rescue NoMethodError
|
165
182
|
# ignored
|
data/lib/libis/tools/version.rb
CHANGED
@@ -542,20 +542,19 @@ module Libis
|
|
542
542
|
#
|
543
543
|
#
|
544
544
|
def method_missing(method, *args, &block)
|
545
|
-
super unless method.to_s =~ /^([a-z_][a-z_0-9]*)(
|
545
|
+
super unless method.to_s =~ /^([a-z_][a-z_0-9]*)(!|=)?$/i
|
546
546
|
node = get_node($1)
|
547
|
-
node = add_node($1)
|
547
|
+
node = add_node($1) if node.nil? || $2 == '!'
|
548
548
|
case args.size
|
549
549
|
when 0
|
550
|
-
node = get_node($1)
|
551
550
|
if block_given?
|
552
551
|
build(node, &block)
|
553
552
|
end
|
554
553
|
when 1
|
555
|
-
if $2
|
556
|
-
node.content = args.first.to_s
|
557
|
-
else
|
554
|
+
if $2.blank?
|
558
555
|
return node[args.first.to_s]
|
556
|
+
else
|
557
|
+
node.content = args.first.to_s
|
559
558
|
end
|
560
559
|
when 2
|
561
560
|
node[args.first.to_s] = args[1].to_s
|
@@ -50,8 +50,8 @@ STR
|
|
50
50
|
|
51
51
|
it 'add dc:date' do
|
52
52
|
dc.date = '2001'
|
53
|
-
dc.dcdate
|
54
|
-
dc.dc_date
|
53
|
+
dc.dcdate! '2002'
|
54
|
+
dc.dc_date! '2003'
|
55
55
|
match_xml dc.document,
|
56
56
|
header +
|
57
57
|
record_start +
|
@@ -62,10 +62,10 @@ STR
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'add dcterms:date' do
|
65
|
-
dc.termsdate
|
66
|
-
dc.dctermsdate
|
67
|
-
dc.terms_date
|
68
|
-
dc.dcterms_date
|
65
|
+
dc.termsdate! '2001'
|
66
|
+
dc.dctermsdate! '2002'
|
67
|
+
dc.terms_date! '2003'
|
68
|
+
dc.dcterms_date! '2004'
|
69
69
|
match_xml dc.document,
|
70
70
|
header +
|
71
71
|
record_start +
|
@@ -106,7 +106,7 @@ describe 'Marc21Record' do
|
|
106
106
|
</dc:record>
|
107
107
|
STR
|
108
108
|
expect(record.to_dc.root).to be_equivalent_to(xml_doc.root).respecting_element_order
|
109
|
-
record.to_dc.elements.each_with_index do |element, i|
|
109
|
+
record.to_dc.root.elements.each_with_index do |element, i|
|
110
110
|
expect(element).to be_equivalent_to(xml_doc.root.elements[i])
|
111
111
|
end
|
112
112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libis-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|