module RestFtpDaemon::CommonHelpers

Public Instance Methods

dashboard_url(filter = '') click to toggle source
# File lib/rest-ftp-daemon/helpers/common.rb, line 20
def dashboard_url filter = ''
  "#{MOUNT_BOARD}/#{filter}"
end
exception_to_error(exception) click to toggle source
# File lib/rest-ftp-daemon/helpers/common.rb, line 32
def exception_to_error exception
  underscore 'err_' + exception.class.name.split('::').last
end
format_bytes(number, unit="", decimals = 0) click to toggle source
# File lib/rest-ftp-daemon/helpers/common.rb, line 4
def format_bytes number, unit="", decimals = 0
  return "Ø" if number.nil? || number.to_f.zero?

  units = ["", "k", "M", "G", "T", "P" ]
  index = ( Math.log(number) / Math.log(2) ).to_i / 10
  converted = number.to_f / (1024 ** index)

  truncated = converted.round(decimals)

  "#{truncated} #{units[index]}#{unit}"
end
identifier(len) click to toggle source
# File lib/rest-ftp-daemon/helpers/common.rb, line 16
def identifier len
  rand(36**len).to_s(36)
end
underscore(camel_cased_word) click to toggle source
# File lib/rest-ftp-daemon/helpers/common.rb, line 24
def underscore camel_cased_word
  camel_cased_word.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end