Class: ROF::Collection
- Inherits:
-
Object
- Object
- ROF::Collection
- Defined in:
- lib/rof/collection.rb
Overview
Called from ROF::Work.process_one_work Can assume type fobject, af-model Collection
Defined Under Namespace
Classes: NoFile
Class Method Summary collapse
- .create_images(obj, image_source) ⇒ Object
-
.find_file_mime(filename) ⇒ Object
extract file extension and determine mime/type.
-
.make_images(subtotal, obj, utility) ⇒ Object
If collection included a file, create launch image and thumbnaile.
-
.make_launch(src_image) ⇒ Object
make collections launch page image.
-
.make_thumb(src_image) ⇒ Object
make thumbnail.
-
.mk_dest_img_name(src_img, dest_name) ⇒ Object
given source image, create destination name for conversion keep same mime type - use dumb mime type determination.
- .process_one_collection(input_obj, utility) ⇒ Object
- .run_convert(src_image, dest_image, options) ⇒ Object
-
.set_convert_path ⇒ Object
figure out where ImageMagick is installed (assumes brew path on MacOS, binary RPM path on Linux).
-
.set_required_fields(obj, utility) ⇒ Object
Set the fields that must be there.
Class Method Details
.create_images(obj, image_source) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rof/collection.rb', line 46 def self.create_images(obj, image_source) launch_img = make_launch(image_source) thumb_img = make_thumb(image_source) raise NoFile if launch_img.nil? || thumb_img.nil? obj['content-file'] = File.basename(launch_img) obj['content-meta'] = { 'mime-type' => find_file_mime(launch_img) } obj['thumbnail-file'] = File.basename(thumb_img) obj['thumbnail-meta'] = { 'mime-type' => find_file_mime(thumb_img) } obj end |
.find_file_mime(filename) ⇒ Object
extract file extension and determine mime/type.
105 106 107 |
# File 'lib/rof/collection.rb', line 105 def self.find_file_mime(filename) MIME::Types.of(filename).first.content_type end |
.make_images(subtotal, obj, utility) ⇒ Object
If collection included a file, create launch image and thumbnaile
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rof/collection.rb', line 31 def self.make_images(subtotal, obj, utility) return subtotal if obj['files'].nil? # verify source image is present in job dir image_source = File.join(utility.workdir, obj['files'][0]) # attempt to create a launch page image and thumbnail # exit if either fails unless File.exist?(image_source) STDERR.print("ROF:Collection.make_images: file ", image_source, " does not exist.\n") raise NoFile end create_images(subtotal, image_source) end |
.make_launch(src_image) ⇒ Object
make collections launch page image
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rof/collection.rb', line 58 def self.make_launch(src_image) = ' -resize 350x350 ' dest_image = mk_dest_img_name(src_image, '-launch') unless run_convert(src_image, dest_image, ) STDERR.print("ROF:Collection.mk_launch: failed on file ", src_image, ".\n") return nil end dest_image end |
.make_thumb(src_image) ⇒ Object
make thumbnail
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rof/collection.rb', line 70 def self.make_thumb(src_image) = ' -resize 256x256 ' dest_image = mk_dest_img_name(src_image, '-thumb') unless run_convert(src_image, dest_image, ) STDERR.print("ROF:Collection.mk_thumb: failed on file ", src_image, ".\n") return nil end dest_image end |
.mk_dest_img_name(src_img, dest_name) ⇒ Object
given source image, create destination name for conversion keep same mime type - use dumb mime type determination
97 98 99 100 101 102 |
# File 'lib/rof/collection.rb', line 97 def self.mk_dest_img_name(src_img, dest_name) dest_part = src_img.split('.') dest_img = dest_part[0] + dest_name dest_img = dest_img + '.' + dest_part[1] if dest_part.length == 2 dest_img end |
.process_one_collection(input_obj, utility) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/rof/collection.rb', line 9 def self.process_one_collection(input_obj, utility) # set the required fields result = set_required_fields(input_obj, utility) result = make_images(result, input_obj, utility) result end |
.run_convert(src_image, dest_image, options) ⇒ Object
81 82 83 84 |
# File 'lib/rof/collection.rb', line 81 def self.run_convert(src_image, dest_image, ) command = set_convert_path + ' ' + src_image + + ' ' + dest_image Kernel.system(command) end |
.set_convert_path ⇒ Object
figure out where ImageMagick is installed (assumes brew path on MacOS, binary RPM path on Linux).
88 89 90 91 92 93 |
# File 'lib/rof/collection.rb', line 88 def self.set_convert_path host_os = RbConfig::CONFIG['sitearch'] return '/usr/local/bin/convert' if host_os.include? 'darwin' '/usr/bin/convert' end |
.set_required_fields(obj, utility) ⇒ Object
Set the fields that must be there
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rof/collection.rb', line 17 def self.set_required_fields(obj, utility) result = {} result['type'] = 'fobject' result['af-model'] = 'Collection' result['rights'] = obj['rights'] result['metadata'] = obj['metadata'] result['pid'] = obj.fetch('pid', utility.next_label) result['rels-ext'] = obj.fetch('rels-ext', {}) result['properties'] = ROF::Utility.prop_ds(obj['owner']) result['properties-meta'] = { 'mime-type' => 'text/xml' } result end |