Class: Assembly::ObjectFile
- Inherits:
-
Object
- Object
- Assembly::ObjectFile
- Includes:
- ObjectFileable
- Defined in:
- lib/assembly-objectfile/object_file.rb,
lib/assembly-objectfile/version.rb
Overview
This class contains generic methods to operate on any file.
Constant Summary collapse
- VERSION =
Project version number
'1.10.2'
Constants included from ObjectFileable
Assembly::ObjectFileable::VALID_MIMETYPE_METHODS
Instance Attribute Summary
Attributes included from ObjectFileable
#file_attributes, #label, #mime_type_order, #path, #provider_md5, #provider_sha1, #relative_path
Class Method Summary collapse
-
.common_path(strings) ⇒ String
Class level method that given an array of strings, return the longest common initial path.
Methods included from ObjectFileable
#dirname, #dpg_basename, #dpg_folder, #encoding, #exif, #exif_mimetype, #ext, #extension_mimetype, #file_exists?, #file_mimetype, #filename, #filename_without_ext, #filesize, #has_color_profile?, #image?, #initialize, #jp2able?, #md5, #mimetype, #object_type, #sha1, #valid_image?
Class Method Details
.common_path(strings) ⇒ String
Class level method that given an array of strings, return the longest common initial path. Useful for removing a common path from a set of filenames when producing content metadata
Example: puts Assembly::ObjectFile.common_prefix() # ‘/Users/peter/0’
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/assembly-objectfile/object_file.rb', line 15 def self.common_path(strings) return nil if strings.empty? n = 0 x = strings.last n += 1 while strings.all? { |s| s[n] && (s[n] == x[n]) } common_prefix = x[0...n] if common_prefix[-1, 1] == '/' # check if last element of the common string is the end of a directory common_prefix # if not, split string along directories, and reject last one else "#{common_prefix.split('/')[0..-2].join('/')}/" # if it was, then return the common prefix directly end end |