Class: Assembly::ObjectFile

Inherits:
Object
  • Object
show all
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.7.1"

Instance Attribute Summary

Attributes included from ObjectFileable

#file_attributes, #label, #path, #provider_md5, #provider_sha1, #relative_path

Class Method Summary collapse

Methods included from ObjectFileable

#dirname, #dpg_basename, #dpg_folder, #encoding, #exif, #ext, #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’

Parameters:

  • strings (Array)

    Array of filenames with paths to operate on

Returns:

  • (String)

    Common part of path of filenames passed in



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/assembly-objectfile/object_file.rb', line 15

def self.common_path(strings)
  return nil if strings.size == 0
  n = 0
  x = strings.last
  n += 1 while strings.all? { |s| s[n] and 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
    return common_prefix.split('/')[0..-2].join('/') + "/"  # if not, split string along directories, and reject last one
  else
    return common_prefix # if it was, then return the common prefix directly
  end
end