Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/evernote-exporter.rb

Instance Method Summary collapse

Instance Method Details

#_to_human_size(num, result = [], index = 0) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/evernote-exporter.rb', line 13

def _to_human_size(num, result = [], index = 0)
  human_units = ['B ', 'K ', 'M ', 'G ', 'T ', 'P ']

  if num >= 1024
    div, mod = num.divmod(1024)
    result.unshift([mod, human_units[index]])
    _to_human_size(div, result, index + 1)
  else
    result.unshift([num, human_units[index]])
  end
end

#number_to_human_size(shortly = false) ⇒ Object



7
8
9
10
11
# File 'lib/evernote-exporter.rb', line 7

def number_to_human_size(shortly = false)
  result = _to_human_size(self.to_i)
  result = result.first(2) if shortly
  result.join.strip
end