Sha256: 825b5a50b155df7330412da49baa2f7965b89f4675cda0f37492a22960502022

Contents?: true

Size: 882 Bytes

Versions: 22

Compression:

Stored size: 882 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 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 'err_' + exception.class.name.split('::').last
    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.435.2 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.435.1 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.435.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.434.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.433.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.432.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.430.1 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.430.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.424.3 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.424.2 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.424.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.423.3 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.423.2 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.423.1 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.423.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.422.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.421.1 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.421.0 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.420.2 lib/rest-ftp-daemon/helpers/common.rb
rest-ftp-daemon-0.420.1 lib/rest-ftp-daemon/helpers/common.rb