Class: IiifPrint::Data::WorkFile
- Inherits:
-
Object
- Object
- IiifPrint::Data::WorkFile
- Defined in:
- lib/iiif_print/data/work_file.rb
Overview
WorkFile is a read-only convenience wrapper for just-in-time
file operations, and is the type of values returned by
IiifPrint::Data::WorkFiles (container) adapter.
Instance Attribute Summary collapse
-
#fileset ⇒ Object
accessors for adaptation relationships:.
-
#parent ⇒ Object
accessors for adaptation relationships:.
-
#work ⇒ Object
accessors for adaptation relationships:.
Class Method Summary collapse
-
.of(work, fileset = nil, parent = nil) ⇒ Object
alternate constructor spelling:.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#data ⇒ String
Read data from working copy of file on local filesystem; checkout file from repository/source as needed.
-
#derivatives ⇒ IiifPrint::Data::WorkDerviatives
Derivatives for fileset associated with this primary file object.
-
#initialize(work, fileset = nil, parent = nil) ⇒ WorkFile
constructor
A new instance of WorkFile.
-
#name ⇒ String
Get filename from stored metadata.
-
#path ⇒ String
Get path to working copy of file on local filesystem; checkout file from repository/source as needed.
-
#unwrapped ⇒ ActiveFedora::File
Get original repository object representing file (not fileset).
-
#with_io {|io| ... } ⇒ Object
Run block/proc upon data of file; checkout file from repository/source as needed.
Constructor Details
#initialize(work, fileset = nil, parent = nil) ⇒ WorkFile
Returns a new instance of WorkFile.
21 22 23 24 25 26 27 28 |
# File 'lib/iiif_print/data/work_file.rb', line 21 def initialize(work, fileset = nil, parent = nil) @work = work # If fileset is nil, presume *first* fileset of work, as in # the single-file-per-work use-case: @fileset = fileset # Parent is WorkFiles (container) object, if applciable: @parent = parent end |
Instance Attribute Details
#fileset ⇒ Object
accessors for adaptation relationships:
12 13 14 |
# File 'lib/iiif_print/data/work_file.rb', line 12 def fileset @fileset end |
#parent ⇒ Object
accessors for adaptation relationships:
12 13 14 |
# File 'lib/iiif_print/data/work_file.rb', line 12 def parent @parent end |
#work ⇒ Object
accessors for adaptation relationships:
12 13 14 |
# File 'lib/iiif_print/data/work_file.rb', line 12 def work @work end |
Class Method Details
.of(work, fileset = nil, parent = nil) ⇒ Object
alternate constructor spelling:
17 18 19 |
# File 'lib/iiif_print/data/work_file.rb', line 17 def self.of(work, fileset = nil, parent = nil) new(work, fileset, parent) end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 40 |
# File 'lib/iiif_print/data/work_file.rb', line 37 def ==(other) return false if @fileset.nil? unwrapped.id == other.unwrapped.id end |
#data ⇒ String
Read data from working copy of file on local filesystem;
checkout file from repository/source as needed.
53 54 55 56 |
# File 'lib/iiif_print/data/work_file.rb', line 53 def data return '' if @fileset.nil? File.read(path, mode: 'rb') end |
#derivatives ⇒ IiifPrint::Data::WorkDerviatives
Derivatives for fileset associated with this primary file object
76 77 78 |
# File 'lib/iiif_print/data/work_file.rb', line 76 def derivatives IiifPrint::Data::WorkDerivatives.of(work, fileset, self) end |
#name ⇒ String
Get filename from stored metadata
69 70 71 72 |
# File 'lib/iiif_print/data/work_file.rb', line 69 def name return nil if @fileset.nil? unwrapped.original_name end |
#path ⇒ String
Get path to working copy of file on local filesystem;
checkout file from repository/source as needed.
45 46 47 48 |
# File 'lib/iiif_print/data/work_file.rb', line 45 def path return nil if @fileset.nil? checkout end |
#unwrapped ⇒ ActiveFedora::File
Get original repository object representing file (not fileset).
32 33 34 35 |
# File 'lib/iiif_print/data/work_file.rb', line 32 def unwrapped return nil if @fileset.nil? @fileset.original_file end |
#with_io {|io| ... } ⇒ Object
Run block/proc upon data of file;
checkout file from repository/source as needed.
61 62 63 64 65 |
# File 'lib/iiif_print/data/work_file.rb', line 61 def with_io(&block) filepath = path return if filepath.nil? File.open(filepath, 'rb', &block) end |