Class: ROF::Filters::Work
- Inherits:
-
ROF::Filter
- Object
- ROF::Filter
- ROF::Filters::Work
- Defined in:
- lib/rof/filters/work.rb
Overview
Expand objects of type “Work(-(.+))?” into a constellation of “fobjects”. Makes a fobject/generic_file for each file adds a depositor turns original object into an fobject/$1 and copies the access to each fobject.
Defined Under Namespace
Classes: NoFile
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Work
constructor
A new instance of Work.
-
#make_thumbnail(result, main_obj, input_obj) ⇒ Object
make the first file be the representative thumbnail.
-
#process(obj_list) ⇒ Object
wade through object list.
-
#process_one_work(input_obj) ⇒ Object
given a single object, return a list (possibly empty) of new objects to replace the one given.
- #set_main_obj(input_obj, model) ⇒ Object
Constructor Details
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
19 20 21 |
# File 'lib/rof/filters/work.rb', line 19 def file_name @file_name end |
Instance Method Details
#make_thumbnail(result, main_obj, input_obj) ⇒ Object
make the first file be the representative thumbnail
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rof/filters/work.rb', line 43 def make_thumbnail(result, main_obj, input_obj) thumb_rep = nil input_obj['files'].each do |finfo| if finfo.is_a?(String) fname = finfo finfo = { 'files' => [fname] } else fname = finfo['files'].first raise NoFile if fname.nil? end finfo['rights'] ||= input_obj['rights'] finfo['owner'] ||= input_obj['owner'] finfo['bendo-item'] ||= input_obj['bendo-item'] finfo['metadata'] ||= { '@context' => ROF::RdfContext } finfo['metadata']['dc:title'] ||= fname mimetype = MIME::Types.of(fname) mimetype = mimetype.empty? ? 'application/octet-stream' : mimetype.first.content_type f_obj = { 'type' => 'fobject', 'af-model' => 'GenericFile', 'pid' => finfo['pid'], 'bendo-item' => finfo['bendo-item'], 'rights' => finfo['rights'], 'properties' => ROF::Utility.prop_ds(finfo['owner']), 'properties-meta' => { 'mime-type' => 'text/xml' }, 'rels-ext' => { 'isPartOf' => [main_obj['pid']] }, 'content-file' => fname, 'content-meta' => { 'label' => fname, 'mime-type' => mimetype }, 'collections' => finfo['collections'], 'metadata' => finfo['metadata'] } f_obj.delete_if { |_k, v| v.nil? } if thumb_rep.nil? thumb_rep = f_obj['pid'] if thumb_rep.nil? thumb_rep = @utility.next_label f_obj['pid'] = thumb_rep end main_obj['properties'] = ROF::Utility.prop_ds(input_obj['owner'], thumb_rep) end result << f_obj end result end |
#process(obj_list) ⇒ Object
wade through object list
22 23 24 25 26 |
# File 'lib/rof/filters/work.rb', line 22 def process(obj_list) @utility.set_workdir(file_name) obj_list.map! { |x| process_one_work(x) } obj_list.flatten! end |
#process_one_work(input_obj) ⇒ Object
given a single object, return a list (possibly empty) of new objects to replace the one given
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rof/filters/work.rb', line 30 def process_one_work(input_obj) model = @utility.decode_work_type(input_obj) return [input_obj] if model.nil? return [ROF::Collection.process_one_collection(input_obj, @utility)] if model == 'Collection' main_obj = set_main_obj(input_obj, model) result = [main_obj] result = make_thumbnail(result, main_obj, input_obj) unless input_obj['files'].nil? result end |
#set_main_obj(input_obj, model) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rof/filters/work.rb', line 97 def set_main_obj(input_obj, model) result = {} result['type'] = 'fobject' result['af-model'] = model result['pid'] = input_obj.fetch('pid', @utility.next_label) result['bendo-item'] = input_obj['bendo-item'] result['rights'] = input_obj['rights'] result['properties'] = ROF::Utility.prop_ds(input_obj['owner']) result['properties-meta'] = { 'mime-type' => 'text/xml' } result['rels-ext'] = input_obj.fetch('rels-ext', {}) result['metadata'] = input_obj['metadata'] result end |