moab-versioning 4.2.1 → 4.2.2

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: 8226ecfe5e815a81aa72bc564fc1abc341b4f570
4
- data.tar.gz: 9d085cad25bc601caec626edb5cf4f778a979fc3
3
+ metadata.gz: 26d64bba0aa593e619713fb761078c032df8e1cc
4
+ data.tar.gz: 91b9bbd3842691aabbc4a9f003347fceeea949f4
5
5
  SHA512:
6
- metadata.gz: 6c0072f1cd34f7bd192a4231b6c496e81d4ce380edaf08cd5fb997b240ad64b09c8ce94ed4083a65f812c11971b1e11eadf2d8099edb898226d904a8e58c3d17
7
- data.tar.gz: 71aa7a0ff75185089d2a7705a13635b67b0fbaa600b438a35fde7f75a4bd83061f050b1c4eeef98162e38b64a66e6c23e3f45748bde93b5de42acaee32fadf9e
6
+ metadata.gz: 94c2ec711d1135684611e517f994658c1358ea01b0687e46c454772476c72b9090250045a79adfb0bc5a8fe0e02988951fbce939eb9891d77956a46c67562cfc
7
+ data.tar.gz: e69e5ee8da7091da76bf6dba56856411da26b683ec5ae897f7c6a6811f5af9e8700a9306e4cd5f75bf20de5e92f0b35b7f87a47753d03fdedaad947f85619e70
@@ -29,7 +29,7 @@
29
29
  # @note Copyright (c) 2012 by The Board of Trustees of the Leland Stanford Junior University.
30
30
  # All rights reserved. See {file:LICENSE.rdoc} for details.
31
31
  module Moab
32
- DEFAULT_CHECKSUM_TYPES = [:md5, :sha1, :sha256].freeze
32
+ DEFAULT_CHECKSUM_TYPES = %i[md5 sha1 sha256].freeze
33
33
  end
34
34
 
35
35
  require 'serializer'
@@ -25,7 +25,7 @@ module Moab
25
25
  @version_inventory = version_inventory
26
26
  @signature_catalog = signature_catalog
27
27
  @bag_pathname = Pathname.new(bag_pathname)
28
- create_bagit_txt()
28
+ create_bagit_txt
29
29
  end
30
30
 
31
31
  # @return [FileInventory] The complete inventory of the files comprising a digital object version
@@ -54,7 +54,7 @@ module Moab
54
54
 
55
55
  # @api internal
56
56
  # @return [void] Generate the bagit.txt tag file
57
- def create_bagit_txt()
57
+ def create_bagit_txt
58
58
  bag_pathname.mkpath
59
59
  bag_pathname.join("bagit.txt").open('w') do |f|
60
60
  f.puts "Tag-File-Character-Encoding: UTF-8"
@@ -63,13 +63,13 @@ module Moab
63
63
  end
64
64
 
65
65
  # @return [NilClass] Delete the bagit files
66
- def delete_bag()
66
+ def delete_bag
67
67
  # make sure this looks like a bag before deleting
68
68
  if bag_pathname.join('bagit.txt').exist?
69
69
  if bag_pathname.join('data').exist?
70
70
  bag_pathname.rmtree
71
71
  else
72
- bag_pathname.children.each { |file| file.delete }
72
+ bag_pathname.children.each(&:delete)
73
73
  bag_pathname.rmdir
74
74
  end
75
75
  end
@@ -77,7 +77,7 @@ module Moab
77
77
  end
78
78
 
79
79
  # @param tar_pathname [Pathname] The location of the tar file (default is based on bag location)
80
- def delete_tarfile()
80
+ def delete_tarfile
81
81
  bag_name = bag_pathname.basename
82
82
  bag_parent = bag_pathname.parent
83
83
  tar_pathname = bag_parent.join("#{bag_name}.tar")
@@ -140,7 +140,7 @@ module Moab
140
140
  # Return true if successful or nil if the group was not found in the inventory
141
141
  def deposit_group(group_id, source_dir)
142
142
  group = bag_inventory.group(group_id)
143
- return nil? if group.nil? or group.files.empty?
143
+ return nil? if group.nil? || group.files.empty?
144
144
  target_dir = bag_pathname.join('data', group_id)
145
145
  group.path_list.each do |relative_path|
146
146
  source = source_dir.join(relative_path)
@@ -157,7 +157,7 @@ module Moab
157
157
  # Return true if successful or nil if the group was not found in the inventory
158
158
  def reconstuct_group(group_id, storage_object_dir)
159
159
  group = bag_inventory.group(group_id)
160
- return nil? if group.nil? or group.files.empty?
160
+ return nil? if group.nil? || group.files.empty?
161
161
  target_dir = bag_pathname.join('data', group_id)
162
162
  group.files.each do |file|
163
163
  catalog_entry = signature_catalog.signature_hash[file.signature]
@@ -183,8 +183,8 @@ module Moab
183
183
  # @api internal
184
184
  # @return [void] Using the checksum information from the inventory, create BagIt manifest files for the payload
185
185
  def create_payload_manifests
186
- manifest_pathname = Hash.new
187
- manifest_file = Hash.new
186
+ manifest_pathname = {}
187
+ manifest_file = {}
188
188
  DEFAULT_CHECKSUM_TYPES.each do |type|
189
189
  manifest_pathname[type] = bag_pathname.join("manifest-#{type}.txt")
190
190
  manifest_file[type] = manifest_pathname[type].open('w')
@@ -205,7 +205,7 @@ module Moab
205
205
  if manifest_file[type]
206
206
  manifest_file[type].close
207
207
  manifest_pathname[type].delete if
208
- manifest_pathname[type].exist? and manifest_pathname[type].size == 0
208
+ manifest_pathname[type].exist? && manifest_pathname[type].size == 0
209
209
  end
210
210
  end
211
211
  end
@@ -222,9 +222,9 @@ module Moab
222
222
 
223
223
  # @api internal
224
224
  # @return [void] create BagIt tag manifest files containing checksums for all files in the bag's root directory
225
- def create_tagfile_manifests()
226
- manifest_pathname = Hash.new
227
- manifest_file = Hash.new
225
+ def create_tagfile_manifests
226
+ manifest_pathname = {}
227
+ manifest_file = {}
228
228
  DEFAULT_CHECKSUM_TYPES.each do |type|
229
229
  manifest_pathname[type] = bag_pathname.join("tagmanifest-#{type}.txt")
230
230
  manifest_file[type] = manifest_pathname[type].open('w')
@@ -243,7 +243,7 @@ module Moab
243
243
  if manifest_file[type]
244
244
  manifest_file[type].close
245
245
  manifest_pathname[type].delete if
246
- manifest_pathname[type].exist? and manifest_pathname[type].size == 0
246
+ manifest_pathname[type].exist? && manifest_pathname[type].size == 0
247
247
  end
248
248
  end
249
249
  end
@@ -260,7 +260,7 @@ module Moab
260
260
  shell_execute(tar_cmd.sub('--force-local', ''))
261
261
  end
262
262
  raise "Unable to create tarfile #{tar_pathname}" unless tar_pathname.exist?
263
- return true
263
+ true
264
264
  end
265
265
 
266
266
  # Executes a system command in a subprocess
@@ -1,5 +1,3 @@
1
- require 'moab'
2
-
3
1
  module Moab
4
2
  # @return [Confstruct::Configuration] the configuration data
5
3
  Config = Confstruct::Configuration.new do
@@ -31,7 +31,7 @@ module Moab
31
31
  }.freeze
32
32
 
33
33
  REQUIRED_MANIFEST_CHECKSUM_TYPE = 'sha256'.freeze
34
- RECOGNIZED_CHECKSUM_ALGORITHMS = [:md5, :sha1, :sha256, :sha384, :sha512].freeze
34
+ RECOGNIZED_CHECKSUM_ALGORITHMS = %i[md5 sha1 sha256 sha384 sha512].freeze
35
35
 
36
36
  TAGMANIFEST = 'tagmanifest'.freeze
37
37
  MANIFEST = 'manifest'.freeze
@@ -1,5 +1,3 @@
1
- require 'moab'
2
-
3
1
  module Moab
4
2
  # A container for a standard subset of a digital objects {FileManifestation} objects
5
3
  # Used to segregate depositor content from repository metadata files
@@ -22,8 +20,9 @@ module Moab
22
20
 
23
21
  # (see Serializable#initialize)
24
22
  def initialize(opts = {})
25
- @signature_hash = Hash.new
23
+ @signature_hash = {}
26
24
  @data_source = ""
25
+ @signatures_from_bag = nil # prevents later warning: instance variable @signatures_from_bag not initialized
27
26
  super(opts)
28
27
  end
29
28
 
@@ -37,7 +36,7 @@ module Moab
37
36
 
38
37
  # @attribute
39
38
  # @return [Integer] The total number of data files (dynamically calculated)
40
- attribute :file_count, Integer, :tag => 'fileCount', :on_save => Proc.new { |i| i.to_s }
39
+ attribute :file_count, Integer, :tag => 'fileCount', :on_save => proc { |i| i.to_s }
41
40
 
42
41
  def file_count
43
42
  files.inject(0) { |sum, manifestation| sum + manifestation.file_count }
@@ -45,7 +44,7 @@ module Moab
45
44
 
46
45
  # @attribute
47
46
  # @return [Integer] The total size (in bytes) of all data files (dynamically calculated)
48
- attribute :byte_count, Integer, :tag => 'byteCount', :on_save => Proc.new { |i| i.to_s }
47
+ attribute :byte_count, Integer, :tag => 'byteCount', :on_save => proc { |i| i.to_s }
49
48
 
50
49
  def byte_count
51
50
  files.inject(0) { |sum, manifestation| sum + manifestation.byte_count }
@@ -53,7 +52,7 @@ module Moab
53
52
 
54
53
  # @attribute
55
54
  # @return [Integer] The total disk usage (in 1 kB blocks) of all data files (estimating du -k result) (dynamically calculated)
56
- attribute :block_count, Integer, :tag => 'blockCount', :on_save => Proc.new { |i| i.to_s }
55
+ attribute :block_count, Integer, :tag => 'blockCount', :on_save => proc { |i| i.to_s }
57
56
 
58
57
  def block_count
59
58
  files.inject(0) { |sum, manifestation| sum + manifestation.block_count }
@@ -61,7 +60,7 @@ module Moab
61
60
 
62
61
  # @return [Array<String>] The data fields to include in summary reports
63
62
  def summary_fields
64
- %w{group_id file_count byte_count block_count}
63
+ %w[group_id file_count byte_count block_count]
65
64
  end
66
65
 
67
66
  # @attribute
@@ -80,7 +79,7 @@ module Moab
80
79
  # @return [Hash<String,FileSignature>] An index of file paths,
81
80
  # used to test for existence of a filename in this file group
82
81
  def path_hash
83
- path_hash = Hash.new
82
+ path_hash = {}
84
83
  signature_hash.each do |signature, manifestation|
85
84
  manifestation.instances.each do |instance|
86
85
  path_hash[instance.path] = signature
@@ -91,14 +90,14 @@ module Moab
91
90
 
92
91
  # @return [Array<String>] The list of file paths in this group
93
92
  def path_list
94
- files.collect { |file| file.instances.collect { |instance| instance.path } }.flatten
93
+ files.collect { |file| file.instances.collect(&:path) }.flatten
95
94
  end
96
95
 
97
96
  # @api internal
98
97
  # @param signature_subset [Array<FileSignature>] The signatures used to select the entries to return
99
98
  # @return [Hash<String,FileSignature>] A pathname,signature hash containing a subset of the filenames in this file group
100
99
  def path_hash_subset(signature_subset)
101
- path_hash = Hash.new
100
+ path_hash = {}
102
101
  signature_subset.each do |signature|
103
102
  manifestation = signature_hash[signature]
104
103
  manifestation.instances.each do |instance|
@@ -132,7 +131,7 @@ module Moab
132
131
  # @return [void] Add a single {FileSignature},{FileInstance} key/value pair to this group.
133
132
  # Data is actually stored in the {#signature_hash}
134
133
  def add_file_instance(signature, instance)
135
- if signature_hash.has_key?(signature)
134
+ if signature_hash.key?(signature)
136
135
  manifestation = signature_hash[signature]
137
136
  else
138
137
  manifestation = FileManifestation.new
@@ -146,7 +145,7 @@ module Moab
146
145
  # @return [void] Remove a file from the inventory
147
146
  # for example, the manifest inventory does not contain a file entry for itself
148
147
  def remove_file_having_path(path)
149
- signature = self.path_hash[path]
148
+ signature = path_hash[path]
150
149
  signature_hash.delete(signature)
151
150
  end
152
151
 
@@ -203,9 +202,8 @@ module Moab
203
202
  pathname = Pathname.new(path).expand_path
204
203
  validated ||= is_descendent_of_base?(pathname)
205
204
  pathname.children.sort.each do |child|
206
- if child.basename.to_s == ".DS_Store"
207
- next
208
- elsif child.directory?
205
+ next if child.basename.to_s == '.DS_Store'
206
+ if child.directory?
209
207
  harvest_directory(child, recursive, validated) if recursive
210
208
  else
211
209
  add_physical_file(child, validated)
@@ -1,5 +1,3 @@
1
- require 'moab'
2
-
3
1
  module Moab
4
2
  # Performs analysis and reports the differences between two matching {FileGroup} objects.
5
3
  # The descending elements of the report hold a detailed breakdown of file-level differences, organized by change type.
@@ -64,7 +62,7 @@ module Moab
64
62
  # @attribute
65
63
  # @return [Integer] the total number of differences found between the two inventories that were
66
64
  # compared (dynamically calculated)
67
- attribute :difference_count, Integer, :tag => 'differenceCount', :on_save => Proc.new { |i| i.to_s }
65
+ attribute :difference_count, Integer, :tag => 'differenceCount', :on_save => proc { |i| i.to_s }
68
66
 
69
67
  def difference_count
70
68
  count = 0
@@ -76,49 +74,49 @@ module Moab
76
74
 
77
75
  # @attribute
78
76
  # @return [Integer] How many files were unchanged
79
- attribute :identical, Integer, :on_save => Proc.new { |n| n.to_s }
77
+ attribute :identical, Integer, :on_save => proc { |n| n.to_s }
80
78
  def identical
81
79
  subset_hash[:identical].count
82
80
  end
83
81
 
84
82
  # @attribute
85
83
  # @return [Integer] How many duplicate copies of files were added
86
- attribute :copyadded, Integer, :on_save => Proc.new { |n| n.to_s }
84
+ attribute :copyadded, Integer, :on_save => proc { |n| n.to_s }
87
85
  def copyadded
88
86
  subset_hash[:copyadded].count
89
87
  end
90
88
 
91
89
  # @attribute
92
90
  # @return [Integer] How many duplicate copies of files were deleted
93
- attribute :copydeleted, Integer, :on_save => Proc.new { |n| n.to_s }
91
+ attribute :copydeleted, Integer, :on_save => proc { |n| n.to_s }
94
92
  def copydeleted
95
93
  subset_hash[:copydeleted].count
96
94
  end
97
95
 
98
96
  # @attribute
99
97
  # @return [Integer] How many files were renamed
100
- attribute :renamed, Integer, :on_save => Proc.new { |n| n.to_s }
98
+ attribute :renamed, Integer, :on_save => proc { |n| n.to_s }
101
99
  def renamed
102
100
  subset_hash[:renamed].count
103
101
  end
104
102
 
105
103
  # @attribute
106
104
  # @return [Integer] How many files were modified
107
- attribute :modified, Integer, :on_save => Proc.new { |n| n.to_s }
105
+ attribute :modified, Integer, :on_save => proc { |n| n.to_s }
108
106
  def modified
109
107
  subset_hash[:modified].count
110
108
  end
111
109
 
112
110
  # @attribute
113
111
  # @return [Integer] How many files were added
114
- attribute :added, Integer, :on_save => Proc.new { |n| n.to_s }
112
+ attribute :added, Integer, :on_save => proc { |n| n.to_s }
115
113
  def added
116
114
  subset_hash[:added].count
117
115
  end
118
116
 
119
117
  # @attribute
120
118
  # @return [Integer] How many files were deleted
121
- attribute :deleted, Integer, :on_save => Proc.new { |n| n.to_s }
119
+ attribute :deleted, Integer, :on_save => proc { |n| n.to_s }
122
120
  def deleted
123
121
  subset_hash[:deleted].count
124
122
  end
@@ -133,19 +131,18 @@ module Moab
133
131
  end
134
132
 
135
133
  def subsets=(array)
136
- if array
137
- array.each { |subset| subset_hash[subset.change.to_sym] = subset }
138
- end
134
+ return unless array
135
+ array.each { |subset| subset_hash[subset.change.to_sym] = subset }
139
136
  end
140
137
 
141
138
  # @return [Array<String>] The data fields to include in summary reports
142
139
  def summary_fields
143
- %w{group_id difference_count identical copyadded copydeleted renamed modified deleted added}
140
+ %w[group_id difference_count identical copyadded copydeleted renamed modified deleted added]
144
141
  end
145
142
 
146
143
  # @api internal
147
144
  # @return [FileGroupDifference] Clone just this element for inclusion in a versionMetadata structure
148
- def summary()
145
+ def summary
149
146
  FileGroupDifference.new(
150
147
  :group_id => group_id,
151
148
  :identical => identical,
@@ -257,7 +254,7 @@ module Moab
257
254
  other_only_paths = other_paths - basis_paths
258
255
  maxsize = [basis_only_paths.size, other_only_paths.size].max
259
256
  (0..maxsize - 1).each do |n|
260
- fid = FileInstanceDifference.new()
257
+ fid = FileInstanceDifference.new
261
258
  fid.basis_path = basis_only_paths[n]
262
259
  fid.other_path = other_only_paths[n]
263
260
  fid.signatures << signature
@@ -331,20 +328,20 @@ module Moab
331
328
  end
332
329
 
333
330
  # @return [Hash<Symbol,Array>] Sets of filenames grouped by change type for use in performing file or metadata operations
334
- def file_deltas()
331
+ def file_deltas
335
332
  # The hash to be returned
336
333
  deltas = Hash.new { |hash, key| hash[key] = [] }
337
334
  # case where other_path is empty or 'same'. (create array of strings)
338
- [:identical, :modified, :deleted, :copydeleted].each do |change|
339
- deltas[change].concat(subset_hash[change].files.collect { |file| file.basis_path })
335
+ %i[identical modified deleted copydeleted].each do |change|
336
+ deltas[change].concat(subset_hash[change].files.collect(&:basis_path))
340
337
  end
341
338
  # case where basis_path and other_path are both present. (create array of arrays)
342
- [:copyadded, :renamed].each do |change|
339
+ %i[copyadded renamed].each do |change|
343
340
  deltas[change].concat(subset_hash[change].files.collect { |file| [file.basis_path, file.other_path] })
344
341
  end
345
342
  # case where basis_path is empty. (create array of strings)
346
343
  [:added].each do |change|
347
- deltas[change].concat(subset_hash[change].files.collect { |file| file.other_path })
344
+ deltas[change].concat(subset_hash[change].files.collect(&:other_path))
348
345
  end
349
346
  deltas
350
347
  end
@@ -1,5 +1,3 @@
1
- require 'moab'
2
-
3
1
  module Moab
4
2
  # A container for reporting a set of file-level differences of the type specified by the change attribute
5
3
  #
@@ -20,7 +18,7 @@ module Moab
20
18
 
21
19
  # (see Serializable#initialize)
22
20
  def initialize(opts = {})
23
- @files = Array.new
21
+ @files = []
24
22
  super(opts)
25
23
  end
26
24
 
@@ -30,7 +28,7 @@ module Moab
30
28
 
31
29
  # @attribute
32
30
  # @return [Integer] How many files were changed
33
- attribute :count, Integer, :on_save => Proc.new { |n| n.to_s }
31
+ attribute :count, Integer, :on_save => proc { |n| n.to_s }
34
32
 
35
33
  def count
36
34
  files.size
@@ -1,5 +1,3 @@
1
- require 'moab'
2
-
3
1
  module Moab
4
2
  # The file path and last modification date properties of a file
5
3
  #
@@ -54,7 +52,7 @@ module Moab
54
52
  # @return [Boolean] Returns true if self and other have the same path.
55
53
  def eql?(other)
56
54
  return false unless other.respond_to?(:path) # Cannot equal an incomparable type!
57
- self.path == other.path
55
+ path == other.path
58
56
  end
59
57
 
60
58
  # @api internal
@@ -1,5 +1,3 @@
1
- require 'moab'
2
-
3
1
  module Moab
4
2
  # A container for recording difference information at the file level
5
3
  # * If there was no change, the change type is set to <i>identical</i>
@@ -28,7 +26,7 @@ module Moab
28
26
 
29
27
  # (see Serializable#initialize)
30
28
  def initialize(opts = {})
31
- @signatures = Array.new
29
+ @signatures = []
32
30
  super(opts)
33
31
  end
34
32
 
@@ -38,11 +36,11 @@ module Moab
38
36
 
39
37
  # @attribute
40
38
  # @return [String] The file's path in the basis inventory (usually for an old version)
41
- attribute :basis_path, String, :tag => 'basisPath', :on_save => Proc.new { |s| s.to_s }
39
+ attribute :basis_path, String, :tag => 'basisPath', :on_save => proc { |s| s.to_s }
42
40
 
43
41
  # @attribute
44
42
  # @return [String] The file's path in the other inventory (usually for an new version) compared against the basis
45
- attribute :other_path, String, :tag => 'otherPath', :on_save => Proc.new { |s| s.to_s }
43
+ attribute :other_path, String, :tag => 'otherPath', :on_save => proc { |s| s.to_s }
46
44
 
47
45
  # @attribute
48
46
  # @return [Array<FileSignature>] The fixity data of the file manifestation(s) (plural if change was a content modification)
@@ -1,5 +1,3 @@
1
- require 'moab'
2
-
3
1
  module Moab
4
2
  # A structured container for recording information about a collection of related files.
5
3
  #
@@ -35,7 +33,7 @@ module Moab
35
33
 
36
34
  # (see Serializable#initialize)
37
35
  def initialize(opts = {})
38
- @groups = Array.new
36
+ @groups = []
39
37
  @inventory_datetime = Time.now
40
38
  super(opts)
41
39
  end
@@ -50,7 +48,7 @@ module Moab
50
48
 
51
49
  # @attribute
52
50
  # @return [Integer] The ordinal version number
53
- attribute :version_id, Integer, :tag => 'versionId', :key => true, :on_save => Proc.new { |n| n.to_s }
51
+ attribute :version_id, Integer, :tag => 'versionId', :key => true, :on_save => proc { |n| n.to_s }
54
52
 
55
53
  # @return [String] The unique identifier concatenating digital object id with version id
56
54
  def composite_key
@@ -71,7 +69,7 @@ module Moab
71
69
 
72
70
  # @attribute
73
71
  # @return [Integer] The total number of data files in the inventory (dynamically calculated)
74
- attribute :file_count, Integer, :tag => 'fileCount', :on_save => Proc.new { |t| t.to_s }
72
+ attribute :file_count, Integer, :tag => 'fileCount', :on_save => proc { |t| t.to_s }
75
73
 
76
74
  def file_count
77
75
  groups.inject(0) { |sum, group| sum + group.file_count }
@@ -79,7 +77,7 @@ module Moab
79
77
 
80
78
  # @attribute
81
79
  # @return [Integer] The total size (in bytes) in all files of all files in the inventory (dynamically calculated)
82
- attribute :byte_count, Integer, :tag => 'byteCount', :on_save => Proc.new { |t| t.to_s }
80
+ attribute :byte_count, Integer, :tag => 'byteCount', :on_save => proc { |t| t.to_s }
83
81
 
84
82
  def byte_count
85
83
  groups.inject(0) { |sum, group| sum + group.byte_count }
@@ -87,7 +85,7 @@ module Moab
87
85
 
88
86
  # @attribute
89
87
  # @return [Integer] The total disk usage (in 1 kB blocks) of all data files (estimating du -k result) (dynamically calculated)
90
- attribute :block_count, Integer, :tag => 'blockCount', :on_save => Proc.new { |t| t.to_s }
88
+ attribute :block_count, Integer, :tag => 'blockCount', :on_save => proc { |t| t.to_s }
91
89
 
92
90
  def block_count
93
91
  groups.inject(0) { |sum, group| sum + group.block_count }
@@ -99,14 +97,14 @@ module Moab
99
97
 
100
98
  # @return [Array<FileGroup] The set of data groups that contain files
101
99
  def non_empty_groups
102
- groups.select { |group| !group.files.empty? }
100
+ groups.reject { |group| group.files.empty? }
103
101
  end
104
102
 
105
103
  # @param non_empty [Boolean] if true, return group_id's only for groups having files
106
104
  # @return [Array<String>] group identifiers contained in this file inventory
107
105
  def group_ids(non_empty = nil)
108
- my_groups = non_empty ? self.non_empty_groups : groups
109
- my_groups.map { |g| g.group_id }
106
+ my_groups = non_empty ? non_empty_groups : groups
107
+ my_groups.map(&:group_id)
110
108
  end
111
109
 
112
110
  # @param [String] group_id The identifer of the group to be selected
@@ -119,12 +117,12 @@ module Moab
119
117
  # @return [Boolean] true if the group is missing or empty
120
118
  def group_empty?(group_id)
121
119
  group = self.group(group_id)
122
- group.nil? or group.files.empty?
120
+ group.nil? || group.files.empty?
123
121
  end
124
122
 
125
123
  # @return [Array<String>] The data fields to include in summary reports
126
124
  def summary_fields
127
- %w{type digital_object_id version_id inventory_datetime file_count byte_count block_count groups}
125
+ %w[type digital_object_id version_id inventory_datetime file_count byte_count block_count groups]
128
126
  end
129
127
 
130
128
  # @param [String] group_id The identifer of the group to be selected
@@ -161,17 +159,9 @@ module Moab
161
159
  def data_source
162
160
  data_source = (groups.collect { |g| g.data_source.to_s }).join('|')
163
161
  if data_source.start_with?('contentMetadata')
164
- if version_id
165
- "v#{version_id}-#{data_source}"
166
- else
167
- "new-#{data_source}"
168
- end
162
+ version_id ? "v#{version_id}-#{data_source}" : "new-#{data_source}"
169
163
  else
170
- if version_id
171
- "v#{version_id}"
172
- else
173
- data_source
174
- end
164
+ version_id ? "v#{version_id}" : data_source
175
165
  end
176
166
  end
177
167
 
@@ -185,7 +175,7 @@ module Moab
185
175
  if group_id
186
176
  groups << FileGroup.new(group_id: group_id).group_from_directory(data_dir)
187
177
  else
188
- ['content', 'metadata'].each do |gid|
178
+ %w[content metadata].each do |gid|
189
179
  groups << FileGroup.new(group_id: gid).group_from_directory(Pathname(data_dir).join(gid))
190
180
  end
191
181
  end
@@ -208,7 +198,7 @@ module Moab
208
198
  # @param bag_pathname [Pathname] The location of the BagIt bag to be inventoried
209
199
  # @return [Hash<Pathname,FileSignature>] The fixity data present in the bag's manifest files
210
200
  def signatures_from_bagit_manifests(bag_pathname)
211
- manifest_pathname = Hash.new
201
+ manifest_pathname = {}
212
202
  DEFAULT_CHECKSUM_TYPES.each do |type|
213
203
  manifest_pathname[type] = bag_pathname.join("manifest-#{type}.txt")
214
204
  end
@@ -235,14 +225,14 @@ module Moab
235
225
  def human_size
236
226
  count = 0
237
227
  size = byte_count
238
- while size >= 1024 and count < 4
228
+ while (size >= 1024) && (count < 4)
239
229
  size /= 1024.0
240
230
  count += 1
241
231
  end
242
232
  if count == 0
243
- sprintf("%d B", size)
233
+ format("%d B", size)
244
234
  else
245
- sprintf("%.2f %s", size, %w[B KB MB GB TB][count])
235
+ format("%.2f %s", size, %w[B KB MB GB TB][count])
246
236
  end
247
237
  end
248
238