Module: Mnogootex::Utils

Defined in:
lib/mnogootex/utils.rb

Class Method Summary collapse

Class Method Details

.dir_size(mask) ⇒ Object



21
22
23
24
# 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) ⇒ Object



14
15
16
17
18
19
# 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) ⇒ Object



7
8
9
10
11
12
# 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