Class: OcflTools::OcflActions
- Inherits:
-
Object
- Object
- OcflTools::OcflActions
- Defined in:
- lib/ocfl_tools/ocfl_actions.rb
Overview
Class for collating manifest actions, both for delta reporting and staging new versions.
Instance Method Summary collapse
-
#actions ⇒ Hash
Convenience method for obtaining a hash of recorded actions.
-
#add(digest, filepath) ⇒ Hash
Creates an ‘add’ entry in the actions hash.
-
#all ⇒ Hash
Convenience method for obtaining a hash recorded of actions.
-
#copy(digest, filepath) ⇒ Hash
Creates a ‘copy’ entry in the actions hash.
-
#delete(digest, filepath) ⇒ Hash
Creates a ‘delete’ entry in the actions hash.
-
#fixity(digest, fixity_algorithm, fixity_digest) ⇒ Hash
Of recorded fixity block.
-
#initialize ⇒ OcflActions
constructor
A new instance of OcflActions.
-
#move(digest, filepath) ⇒ Hash
Creates a ‘move’ entry in the actions hash.
-
#update(digest, filepath) ⇒ Hash
Creates an ‘update’ entry in the actions hash.
-
#update_manifest(digest, filepath) ⇒ Hash
Creates an ‘update_manifest’ entry in the actions hash.
Constructor Details
#initialize ⇒ OcflActions
Returns a new instance of OcflActions.
6 7 8 9 10 11 12 13 14 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 6 def initialize @my_actions = {} @my_actions['update_manifest'] = {} @my_actions['add'] = {} @my_actions['update'] = {} @my_actions['copy'] = {} @my_actions['move'] = {} @my_actions['delete'] = {} end |
Instance Method Details
#actions ⇒ Hash
Convenience method for obtaining a hash of recorded actions.
18 19 20 21 22 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 18 def actions # Don't return empty keys. @my_actions.delete_if { |_k, v| v == {} } @my_actions end |
#add(digest, filepath) ⇒ Hash
Creates an ‘add’ entry in the actions hash.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 52 def add(digest, filepath) if @my_actions['add'].key?(digest) == false @my_actions['add'][digest] = [] end # Only put unique values into filepaths if @my_actions['add'][digest].include?(filepath) return @my_actions['add'][digest] else @my_actions['add'][digest] = (@my_actions['add'][digest] << filepath) end end |
#all ⇒ Hash
Convenience method for obtaining a hash recorded of actions.
26 27 28 29 30 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 26 def all # Don't return empty keys. @my_actions.delete_if { |_k, v| v == {} } @my_actions end |
#copy(digest, filepath) ⇒ Hash
Creates a ‘copy’ entry in the actions hash.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 84 def copy(digest, filepath) if @my_actions['copy'].key?(digest) == false @my_actions['copy'][digest] = [] end # Only put unique values into filepaths if @my_actions['copy'][digest].include?(filepath) return @my_actions['copy'][digest] else @my_actions['copy'][digest] = (@my_actions['copy'][digest] << filepath) end end |
#delete(digest, filepath) ⇒ Hash
Creates a ‘delete’ entry in the actions hash.
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 116 def delete(digest, filepath) if @my_actions['delete'].key?(digest) == false @my_actions['delete'][digest] = [] end # Only put unique values into filepaths if @my_actions['delete'][digest].include?(filepath) return @my_actions['delete'][digest] else @my_actions['delete'][digest] = (@my_actions['delete'][digest] << filepath) end end |
#fixity(digest, fixity_algorithm, fixity_digest) ⇒ Hash
Returns of recorded fixity block.
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 132 def fixity(digest, fixity_algorithm, fixity_digest) # Only create this key if used. @my_actions['fixity'] = {} if @my_actions.key?('fixity') == false if @my_actions['fixity'].key?(fixity_algorithm) == false @my_actions['fixity'][fixity_algorithm] = {} end # only add unique fixity digests. if @my_actions['fixity'][fixity_algorithm].include?(digest) return @my_actions['fixity'][fixity_algorithm][digest] else @my_actions['fixity'][fixity_algorithm][digest] = fixity_digest end end |
#move(digest, filepath) ⇒ Hash
Creates a ‘move’ entry in the actions hash.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 100 def move(digest, filepath) if @my_actions['move'].key?(digest) == false @my_actions['move'][digest] = [] end # Only put unique values into filepaths if @my_actions['move'][digest].include?(filepath) return @my_actions['move'][digest] else @my_actions['move'][digest] = (@my_actions['move'][digest] << filepath) end end |
#update(digest, filepath) ⇒ Hash
Creates an ‘update’ entry in the actions hash.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 68 def update(digest, filepath) if @my_actions['update'].key?(digest) == false @my_actions['update'][digest] = [] end # Only put unique values into filepaths if @my_actions['update'][digest].include?(filepath) return @my_actions['update'][digest] else @my_actions['update'][digest] = (@my_actions['update'][digest] << filepath) end end |
#update_manifest(digest, filepath) ⇒ Hash
Creates an ‘update_manifest’ entry in the actions hash.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ocfl_tools/ocfl_actions.rb', line 36 def update_manifest(digest, filepath) if @my_actions['update_manifest'].key?(digest) == false @my_actions['update_manifest'][digest] = [] end # Only put unique values into filepaths if @my_actions['update_manifest'][digest].include?(filepath) return @my_actions['update_manifest'][digest] else @my_actions['update_manifest'][digest] = (@my_actions['update_manifest'][digest] << filepath) end end |