Class: Hyrax::DerivativePath
- Inherits:
-
Object
- Object
- Hyrax::DerivativePath
- Defined in:
- app/services/hyrax/derivative_path.rb
Instance Attribute Summary collapse
-
#destination_name ⇒ Object
readonly
Returns the value of attribute destination_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.derivative_path_for_reference(object, destination_name) ⇒ Object
Path on file system where derivative file is stored.
-
.derivatives_for_reference(object) ⇒ Array<String>
Array of paths to derivatives for this object.
Instance Method Summary collapse
- #all_paths ⇒ Object
- #derivative_path ⇒ Object
-
#initialize(object, destination_name = nil) ⇒ DerivativePath
constructor
A new instance of DerivativePath.
- #pair_directory ⇒ Object
- #pair_path ⇒ Object
- #pairs ⇒ Object
Constructor Details
#initialize(object, destination_name = nil) ⇒ DerivativePath
Returns a new instance of DerivativePath.
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_name ⇒ Object (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 |
#id ⇒ Object (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
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.
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_paths ⇒ Object
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_path ⇒ Object
28 29 30 |
# File 'app/services/hyrax/derivative_path.rb', line 28 def derivative_path "#{path_prefix}-#{file_name}" end |
#pair_directory ⇒ Object
42 43 44 |
# File 'app/services/hyrax/derivative_path.rb', line 42 def pair_directory pairs[0..-2] end |
#pair_path ⇒ Object
46 47 48 |
# File 'app/services/hyrax/derivative_path.rb', line 46 def pair_path (pair_directory + pairs[-1..-1]).join('/') end |
#pairs ⇒ Object
38 39 40 |
# File 'app/services/hyrax/derivative_path.rb', line 38 def pairs @pairs ||= id.split('').each_slice(2).map(&:join) end |