Sha256: 71501059f75706582efb521a661d0150662ba6a69902405d6a81e571b7f0272e

Contents?: true

Size: 830 Bytes

Versions: 4

Compression:

Stored size: 830 Bytes

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 tokenize item
      return unless item.is_a? String
      "[#{item}]"
    end

    def dashboard_url filter = ''
      "#{MOUNT_BOARD}/#{filter}"
    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

4 entries across 4 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.400.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.306.4 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.306.3 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.306.1 lib/rest-ftp-daemon/helpers/common.rb