module Mnogootex::Utils
Public Class Methods
dir_size(mask)
click to toggle source
# File lib/mnogootex/utils.rb, line 21 def self.dir_size(mask) Dir.glob(Pathname.new(mask).join('**', '*')). map! { |f| Pathname.new(f).size }.inject(:+) || 0 end
humanize_bytes(size)
click to toggle source
# File lib/mnogootex/utils.rb, line 14 def self.humanize_bytes(size) %w[b Kb Mb Gb Tb Pb Eb Zb Yb].reduce(size) do |magnitude, unit| break "#{magnitude}#{unit}" if magnitude < 1024 magnitude / 1024 end end
short_md5(input)
click to toggle source
# File lib/mnogootex/utils.rb, line 7 def self.short_md5(input) [Digest::MD5.digest(input)]. # get 16 bytes of MD5 pack('m0'). # pack them into 22+2 base64 bytes (w/o trailing newline) tr('+/', '-_'). # make then url/path-safe chomp('==') # drop last 2 padding bytes end