lib/file_distribution.rb in file_distribution-0.1.1 vs lib/file_distribution.rb in file_distribution-0.2.0
- old
+ new
@@ -18,37 +18,35 @@
end
# Params:
# - ext: file extension.
def set_extension(ext)
- if ext.length > 0 && ext.chars.first != '.'
- @ext = '.' + ext
- else
- @ext = ext
- end
+ @ext = ext
+
+ @ext = sprintf('.%s', ext) if !ext.empty? && ext.chars.first != '.'
end
# Returns Destination path.
def get_path
@path
end
# Params:
# - id: database file ID etc.
def hex_path(id)
- hex = "%x" % id
- hex = '0%s' % hex if hex.length % 2 != 0
- @path = File.join(@prefix,hex.scan(/../))
+ hex = sprintf('%x', id)
+ hex = sprintf('0%s', hex) if hex.length.odd?
+ @path = File.join(@prefix, hex.scan(/../))
@path += @ext
end
# Params:
# - path: source file path.
#
- # Raises a SystemCallError if the file cannot be renamed.
+ # Raise a SystemCallError if the file cannot be renamed.
def rename_from(path)
dst_dir = File.dirname(@path)
- FileUtils.mkpath(dst_dir) unless File.exists?(dst_dir)
+ FileUtils.mkpath(dst_dir) unless File.exist?(dst_dir)
- File.rename(path,@path)
+ File.rename(path, @path)
end
end