Sha256: 913495a290d87969704120411216ed2a103269fb2f4fcdb02e5402e4963356a9

Contents?: true

Size: 766 Bytes

Versions: 98

Compression:

Stored size: 766 Bytes

Contents

module Vmail
  DIVIDER_WIDTH = 46
  UNITS = [:b, :k, :M, :G].freeze

  module Helpers

    def retry_if_needed
      res = nil
      3.times do
        res = yield
        break if res
      end
      res
    end

    # borrowed from ActionView/Helpers
    def number_to_human_size(number)
      if number.to_i < 1024
        "< 1k" # round up to 1kh
      else
        max_exp = UNITS.size - 1
        exponent = (Math.log(number) / Math.log(1024)).to_i # Convert to base 1024
        exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
        number  /= 1024 ** exponent
        unit = UNITS[exponent]
        "#{number}#{unit}"
      end
    end
    

    def divider(str)
      str * DIVIDER_WIDTH
    end


  end
end

Version data entries

98 entries across 98 versions & 1 rubygems

Version Path
vmail-2.8.7 lib/vmail/helpers.rb
vmail-2.8.6 lib/vmail/helpers.rb
vmail-2.8.5 lib/vmail/helpers.rb
vmail-2.8.4 lib/vmail/helpers.rb
vmail-2.8.2 lib/vmail/helpers.rb
vmail-2.8.1 lib/vmail/helpers.rb
vmail-2.8.0 lib/vmail/helpers.rb
vmail-2.7.8 lib/vmail/helpers.rb
vmail-2.7.7 lib/vmail/helpers.rb
vmail-2.7.6 lib/vmail/helpers.rb
vmail-2.7.5 lib/vmail/helpers.rb
vmail-2.7.4 lib/vmail/helpers.rb
vmail-2.7.3 lib/vmail/helpers.rb
vmail-2.7.1 lib/vmail/helpers.rb
vmail-2.7.0 lib/vmail/helpers.rb
vmail-2.6.9 lib/vmail/helpers.rb
vmail-2.6.7 lib/vmail/helpers.rb
vmail-2.6.6 lib/vmail/helpers.rb
vmail-2.6.5 lib/vmail/helpers.rb
vmail-2.6.4 lib/vmail/helpers.rb