Class: IiifPrint::Data::WorkFiles
- Inherits:
-
Object
- Object
- IiifPrint::Data::WorkFiles
- Includes:
- PathHelper
- Defined in:
- lib/iiif_print/data/work_files.rb
Instance Attribute Summary collapse
-
#assigned ⇒ Object
Returns the value of attribute assigned.
-
#unassigned ⇒ Object
Returns the value of attribute unassigned.
-
#work ⇒ Object
Returns the value of attribute work.
Class Method Summary collapse
-
.assign!(to:, path:, derivative_paths: [], commit: true) ⇒ Object
A convenience method to associate files (original and derivatives) to the given work.
-
.of(work) ⇒ Object
alternate constructor spelling:.
Instance Method Summary collapse
-
#assign(path) ⇒ Object
Assign a path to assigned queue for attachment.
-
#commit! ⇒ Object
commit pending changes to work files beginning with removals, then with new assignments.
-
#derivatives(fileset: nil) ⇒ IiifPrint::Data::WorkDerviatives
Derivatives for specified fileset or first fileset found.
-
#entries ⇒ Array<Array>
Array of [id, WorkFile] for each primary file.
-
#get(name_or_id) ⇒ IiifPrint::Data::WorkFile
(also: #[])
Get a WorkFile adapter representing primary file, either by name or id.
-
#initialize(work) ⇒ WorkFiles
constructor
A new instance of WorkFiles.
-
#keys ⇒ String
List of fileset (not file) id keys, presumes system like Hyrax is only keeping a 1:1 between fileset and contained PCDM file, because derivatives are not stored in the FileSet.
-
#names ⇒ Array<String>
List of local file names for attachments, based on original ingested or uploaded file name.
-
#state ⇒ String
Assignment state.
-
#unassign(name_or_id) ⇒ Object
Assign a name or id to unassigned queue for deletion – OR – remove a path from queue of assigned items.
-
#values ⇒ Array<IiifPrint::Data::WorkFile>
List of WorkFile for each primary file.
Methods included from PathHelper
#isuri?, #normalize_path, #path_to_uri, #registered_ingest_path, #validate_path
Constructor Details
#initialize(work) ⇒ WorkFiles
Returns a new instance of WorkFiles.
32 33 34 35 36 37 |
# File 'lib/iiif_print/data/work_files.rb', line 32 def initialize(work) @work = work @assigned = [] @unassigned = [] @derivatives = nil end |
Instance Attribute Details
#assigned ⇒ Object
Returns the value of attribute assigned.
6 7 8 |
# File 'lib/iiif_print/data/work_files.rb', line 6 def assigned @assigned end |
#unassigned ⇒ Object
Returns the value of attribute unassigned.
6 7 8 |
# File 'lib/iiif_print/data/work_files.rb', line 6 def unassigned @unassigned end |
#work ⇒ Object
Returns the value of attribute work.
6 7 8 |
# File 'lib/iiif_print/data/work_files.rb', line 6 def work @work end |
Class Method Details
.assign!(to:, path:, derivative_paths: [], commit: true) ⇒ Object
A convenience method to associate files (original and derivatives) to the given work.
23 24 25 26 27 28 29 30 |
# File 'lib/iiif_print/data/work_files.rb', line 23 def self.assign!(to:, path:, derivative_paths: [], commit: true) = new(to) .assign(path) Array.wrap(derivative_paths).each do |derivative_path| .derivatives.assign(derivative_path) end .commit! if commit end |
.of(work) ⇒ Object
alternate constructor spelling:
10 11 12 |
# File 'lib/iiif_print/data/work_files.rb', line 10 def self.of(work) new(work) end |
Instance Method Details
#assign(path) ⇒ Object
Assign a path to assigned queue for attachment
110 111 112 113 114 |
# File 'lib/iiif_print/data/work_files.rb', line 110 def assign(path) path = normalize_path(path) validate_path(path) @assigned.push(path) end |
#commit! ⇒ Object
commit pending changes to work files
beginning with removals, then with new assignments
128 129 130 131 |
# File 'lib/iiif_print/data/work_files.rb', line 128 def commit! commit_unassigned commit_assigned end |
#derivatives(fileset: nil) ⇒ IiifPrint::Data::WorkDerviatives
Derivatives for specified fileset or first fileset found.
The `WorkDerivatives` adapter as assign/commmit! semantics just
like `WorkFiles`, and also acts like a hash/mapping of
destination names (usually file extension) to path of saved
derviative. Always returns same instance (memoized after first
use) of `WorkDerivatives`.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/iiif_print/data/work_files.rb', line 46 def derivatives(fileset: nil) fileset ||= @fileset return @derivatives unless @derivatives.nil? if fileset.nil? # for the deferred assignement case, we have no fileset yet... work_file = IiifPrint::Data::WorkFile.of(work, nil, self) return work_file.derivatives end # Otherwise, delegate actual construction to WorkFile.derivatives: @derivatives = values[0].derivatives end |
#entries ⇒ Array<Array>
Array of [id, WorkFile] for each primary file
88 89 90 |
# File 'lib/iiif_print/data/work_files.rb', line 88 def entries filesets.map { |fs| [fs.id, self[fs.id]] } end |
#get(name_or_id) ⇒ IiifPrint::Data::WorkFile Also known as: []
Get a WorkFile adapter representing primary file, either by name or id
103 104 105 106 |
# File 'lib/iiif_print/data/work_files.rb', line 103 def get(name_or_id) return get_by_fileset_id(name_or_id) if keys.include?(name_or_id) get_by_filename(name_or_id) end |
#keys ⇒ String
List of fileset (not file) id keys, presumes system like Hyrax
is only keeping a 1:1 between fileset and contained PCDM file,
because derivatives are not stored in the FileSet.
75 76 77 |
# File 'lib/iiif_print/data/work_files.rb', line 75 def keys filesets.map(&:id) end |
#names ⇒ Array<String>
List of local file names for attachments, based on original ingested
or uploaded file name.
95 96 97 |
# File 'lib/iiif_print/data/work_files.rb', line 95 def names filesets.map(&method(:original_name)) end |
#state ⇒ String
Assignment state
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/iiif_print/data/work_files.rb', line 60 def state return 'dirty' unless @assigned.empty? && @unassigned.empty? return 'empty' if keys.empty? # TODO: implement 'pending' as intermediate state between 'dirty' # and saved, where we look for saved state that matches what was # previously assigned in THIS instance. We can only know that # changes initiated by this instance in this thread are pending # because there's no global storage for the assignment queue. 'saved' end |
#unassign(name_or_id) ⇒ Object
Assign a name or id to unassigned queue for deletion – OR – remove a
path from queue of assigned items
119 120 121 122 123 124 |
# File 'lib/iiif_print/data/work_files.rb', line 119 def unassign(name_or_id) # if name_or_id is queued path, remove from @assigned queue: @assigned.delete(name_or_id) if @assigned.include?(name_or_id) # if name_or_id is known id or name, remove @unassigned.push(name_or_id) if include?(name_or_id) end |
#values ⇒ Array<IiifPrint::Data::WorkFile>
List of WorkFile for each primary file
82 83 84 |
# File 'lib/iiif_print/data/work_files.rb', line 82 def values keys.map(&method(:get)) end |