Class: CurationConcerns::DerivativePath

Inherits:
Object
  • Object
show all
Defined in:
app/services/curation_concerns/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)


22
23
24
25
# File 'app/services/curation_concerns/derivative_path.rb', line 22

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

Instance Attribute Details

#destination_nameObject (readonly)

Returns the value of attribute destination_name.



3
4
5
# File 'app/services/curation_concerns/derivative_path.rb', line 3

def destination_name
  @destination_name
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'app/services/curation_concerns/derivative_path.rb', line 3

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

  • destintation_name (String)


9
10
11
# File 'app/services/curation_concerns/derivative_path.rb', line 9

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:

  • object (ActiveFedora::Base or String)

    either the AF object or its id

Returns:

  • (Array<String>)

    Array of paths to derivatives for this object.



15
16
17
# File 'app/services/curation_concerns/derivative_path.rb', line 15

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

Instance Method Details

#all_pathsObject



31
32
33
34
35
# File 'app/services/curation_concerns/derivative_path.rb', line 31

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

#derivative_pathObject



27
28
29
# File 'app/services/curation_concerns/derivative_path.rb', line 27

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