Module: Vmail::Helpers

Included in:
ImapClient
Defined in:
lib/vmail/helpers.rb

Instance Method Summary collapse

Instance Method Details

#divider(str) ⇒ Object



31
32
33
# File 'lib/vmail/helpers.rb', line 31

def divider(str)
  str * DIVIDER_WIDTH
end

#number_to_human_size(number) ⇒ Object

borrowed from ActionView/Helpers



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vmail/helpers.rb', line 17

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

#retry_if_neededObject



7
8
9
10
11
12
13
14
# File 'lib/vmail/helpers.rb', line 7

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