1 module CollectionsHelper
4 {source: x.tail_uuid, target: x.head_uuid, type: x.name}
9 # Regex match for collection UUIDs, returns a regex match object with the
10 # hash in group 1, (optional) size in group 2, (optional) subsequent uuid
11 # fields in group 3, and (optional) file path within the collection as group
12 # 4; or nil for no match.
14 # +uuid+ the uuid string to match
17 /^([a-f0-9]{32})(\+[0-9]+)?(\+.*?)?(\/.*)?$/.match(uuid.to_s)
21 # Regex match for collection UUID or "UUID/file" path.
22 # Returns a regex match object with the
23 # UUID in group 1, (optional) file path in group 2; or nil for no match.
25 def self.match_uuid_with_optional_filepath(uuid_with_optional_file)
26 /^([0-9a-z]{5}-[0-9a-z]{5}-[0-9a-z]{15})(\/*.*)$/.match(uuid_with_optional_file.to_s)
30 # Regex match for common image file extensions, returns a regex match object
31 # with the matched extension in group 1; or nil for no match.
33 # +file+ the file string to match
35 def self.is_image file
36 /\.(jpg|jpeg|gif|png|svg)$/i.match(file)
40 # Generates a relative file path than can be appended to the URL of a
41 # collection to get a file download link without adding a spurious ./ at the
42 # beginning for files in the default stream.
44 # +file+ an entry in the Collection.files list in the form [stream, name, size]
46 def self.file_path file
49 f0 = f0[2..-1] if f0[0..1] == './'
50 f0 += '/' if not f0.empty?
51 file_path = "#{f0}#{file[1]}"