Module: WatchmonkeyCli::Helper

Included in:
Application
Defined in:
lib/watchmonkey_cli/helper.rb

Constant Summary collapse

BYTE_UNITS =
%W(TiB GiB MiB KiB B).freeze

Instance Method Summary collapse

Instance Method Details

#human_filesize(s) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/watchmonkey_cli/helper.rb', line 5

def human_filesize(s)
  s = s.to_f
  i = BYTE_UNITS.length - 1
  while s > 512 && i > 0
    i -= 1
    s /= 1024
  end
  ((s > 9 || s.modulo(1) < 0.1 ? '%d' : '%.1f') % s) + ' ' + BYTE_UNITS[i]
end

#human_number(n) ⇒ Object



15
16
17
# File 'lib/watchmonkey_cli/helper.rb', line 15

def human_number(n)
  n.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse
end