Class: Hyrax::DerivativePath

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/derivative_path.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, destination_name = nil) ⇒ DerivativePath

Returns a new instance of DerivativePath.

Parameters:

  • object (ActiveFedora::Base, String)

    either the AF object or its id

  • destination_name (String) (defaults to: nil)


23
24
25
26
# File 'app/services/hyrax/derivative_path.rb', line 23

def initialize(object, destination_name = nil)
  @id = object.is_a?(String) ? object : object.id.to_s
  @destination_name = destination_name.gsub(/^original_file_/, '') if destination_name
end

Instance Attribute Details

#destination_nameObject (readonly)

Returns the value of attribute destination_name.



4
5
6
# File 'app/services/hyrax/derivative_path.rb', line 4

def destination_name
  @destination_name
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'app/services/hyrax/derivative_path.rb', line 4

def id
  @id
end

Class Method Details

.derivative_path_for_reference(object, destination_name) ⇒ Object

Path on file system where derivative file is stored

Parameters:

  • object (ActiveFedora::Base or String)

    either the AF object or its id

  • destination_name (String)


10
11
12
# File 'app/services/hyrax/derivative_path.rb', line 10

def derivative_path_for_reference(object, destination_name)
  new(object, destination_name).derivative_path
end

.derivatives_for_reference(object) ⇒ Array<String>

Returns Array of paths to derivatives for this object.

Parameters:

Returns:

  • (Array<String>)

    Array of paths to derivatives for this object.



16
17
18
# File 'app/services/hyrax/derivative_path.rb', line 16

def derivatives_for_reference(object)
  new(object).all_paths
end

Instance Method Details

#all_pathsObject



32
33
34
35
36
# File 'app/services/hyrax/derivative_path.rb', line 32

def all_paths
  Dir.glob(root_path.join("*")).select do |path|
    path.start_with?(path_prefix.to_s)
  end
end

#derivative_pathObject



28
29
30
# File 'app/services/hyrax/derivative_path.rb', line 28

def derivative_path
  "#{path_prefix}-#{file_name}"
end

#pair_directoryObject



42
43
44
# File 'app/services/hyrax/derivative_path.rb', line 42

def pair_directory
  pairs[0..-2]
end

#pair_pathObject



46
47
48
# File 'app/services/hyrax/derivative_path.rb', line 46

def pair_path
  (pair_directory + pairs[-1..-1]).join('/')
end

#pairsObject



38
39
40
# File 'app/services/hyrax/derivative_path.rb', line 38

def pairs
  @pairs ||= id.split('').each_slice(2).map(&:join)
end