Module: Poleica::Pathable

Included in:
Polei
Defined in:
lib/poleica/pathable.rb

Overview

Path methods

Instance Method Summary collapse

Instance Method Details

#extensionObject



13
14
15
# File 'lib/poleica/pathable.rb', line 13

def extension
  File.extname(path)[1..-1] || ''
end

#nameObject



17
18
19
# File 'lib/poleica/pathable.rb', line 17

def name
  File.basename(path, ".#{extension}")
end

#path_for_extension(extension) ⇒ Object



5
6
7
# File 'lib/poleica/pathable.rb', line 5

def path_for_extension(extension)
  "#{path_without_extension}.#{extension}"
end

#path_with_md5(extension = self.extension) ⇒ Object



21
22
23
24
25
26
# File 'lib/poleica/pathable.rb', line 21

def path_with_md5(extension = self.extension)
  data   = File.read(path)
  md5    = Digest::MD5.new
  digest = md5.hexdigest(data)
  "#{path_without_extension}-#{digest}.#{extension}"
end

#path_without_extensionObject



9
10
11
# File 'lib/poleica/pathable.rb', line 9

def path_without_extension
  File.join(File.dirname(path), File.basename(path, '.*'))
end