Class: Concord::FilenameGenerators::DiyGenerator

Inherits:
DefaultGenerator show all
Defined in:
lib/concord/filename_generators/diy_generator.rb

Class Method Summary collapse

Methods inherited from DefaultGenerator

next_sequence

Class Method Details

.generate_filename(resource) ⇒ Object

Raises:

  • (::ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/concord/filename_generators/diy_generator.rb', line 6

def self.generate_filename(resource)
  return "#{resource.extras[:activity].uuid}.otml" if resource.extras && resource.extras[:activity]
  raise ::ArgumentError, "Resource must have a valid URI" unless resource.uri && resource.uri.kind_of?(::URI)
  uri = resource.uri
  uri_path = uri.path.split('/')
  uri_path = ["","index.html"] if uri_path.size == 0
  uri_path.unshift("") if uri_path.size == 1
  file_ext = uri_path[-1].split('.')[-1]
  file = ::Digest::SHA1.hexdigest(uri.to_s)
  file += ".#{file_ext}" if file_ext
  return file
end