Sha256: 81aa450bdad68da0071f6a3593641a34d4a28fca198528c9db583fa29f82a2bf

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

module RestFtpDaemon
  module CommonHelpers

    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

    def identifier len
      rand(36**len).to_s(36)
    end

    def dashboard_url filter = ''
      "#{MOUNT_BOARD}/#{filter}"
    end

    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

    def exception_to_error exception
      underscore exception.class.name.split('::').last
    end

    # Dates and times: date with time generator
    # def datetime_full datetime
    #   return "-"  if datetime.nil?
    #   datetime.to_datetime.strftime("%d.%m.%Y %H:%M:%S")
    # end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.410.2 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.410.1 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.410.0.pre.1 lib/rest-ftp-daemon/helpers/common.rb