Class: ActiveFedora::FilePathBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/file_path_builder.rb

Class Method Summary collapse

Class Method Details

.build(digital_object, name, prefix) ⇒ Object

Builds a relative path for a file

[View source]

4
5
6
7
8
# File 'lib/active_fedora/file_path_builder.rb', line 4

def self.build(digital_object, name, prefix)
  name = nil if name == ''
  prefix ||= 'DS'
  name || generate_dsid(digital_object, prefix)
end

.format_dsid(prefix, suffix) ⇒ Object

Provided so that an application can override how generated ids are formatted (e.g DS01 instead of DS1)

[View source]

23
24
25
# File 'lib/active_fedora/file_path_builder.rb', line 23

def self.format_dsid(prefix, suffix)
  format "%s%i", prefix, suffix
end

.generate_dsid(digital_object, prefix) ⇒ Object

return a valid dsid that is not currently in use. Uses a prefix (default “DS”) and an auto-incrementing integer Example: if there are already datastreams with IDs DS1 and DS2, this method will return DS3. If you specify FOO as the prefix, it will return FOO1.

[View source]

12
13
14
15
16
17
18
19
20
# File 'lib/active_fedora/file_path_builder.rb', line 12

def self.generate_dsid(digital_object, prefix)
  return unless digital_object
  matches = digital_object.attached_files.keys.map do |d|
    data = /^#{prefix}(\d+)$/.match(d)
    data && data[1].to_i
  end.compact
  val = matches.empty? ? 1 : matches.max + 1
  format_dsid(prefix, val)
end