Class: Aspera::IdGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/id_generator.rb

Class Method Summary collapse

Class Method Details

.from_list(object_id) ⇒ String

Generate an ID from a list of object IDs The generated ID is safe as file name

Parameters:

Returns:

  • (String)

    the generated ID



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/aspera/id_generator.rb', line 14

def from_list(object_id)
  safe_char = Environment.instance.safe_filename_character
  if object_id.is_a?(Array)
    # compact: remove nils
    object_id = object_id.flatten.compact.map do |i|
      i.is_a?(String) && i.start_with?('https://') ? URI.parse(i).host : i.to_s
    end.join(safe_char)
  end
  Aspera.assert_type(object_id, String)
  # keep dot for extension only (nicer)
  return Environment.instance.sanitized_filename(object_id.gsub('.', safe_char)).downcase
end