Class: Measured

Inherits:
Object
  • Object
show all
Defined in:
lib/pve/helper.rb

Defined Under Namespace

Classes: V

Class Method Summary collapse

Class Method Details

.bytes1(v) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/pve/helper.rb', line 26

def bytes1 v
  v = v.to_f
  return units '%d ' % v , :B  if 512 > v
  %w[KiB MiBy GiByt TiByte ExiByte PetiByte].each_with_index do |m|
    v /= 1024
    return units '%.1f ' % v, m  if 512 > v
  end
  units '%d ' % v, :PetiByte
end

.bytes2(v) ⇒ Object Also known as: bytes



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pve/helper.rb', line 36

def bytes2 v
  r = (v.to_i / 1024 / 1024).to_s
  return '·'  if 0 == r
  r.
    reverse.
    each_char.
    each_slice( 3).
    to_a.
    reverse.
    map {|a| a.reverse.join }.
    join " "
end

.seconds(i) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pve/helper.rb', line 55

def seconds i
  i = i.to_i
  return V.new "\e[1;30m·\e[0m", 1  if 0 == i
  return units '%d ' % i, :s  if 90 > i
  i /= 60
  return units '%d ' % i, :mi  if 90 > i
  i /= 60
  return units '%d ' % i, :hou  if 36 > i
  i /= 24
  return units '%d ' % i, :days  if 14 > i
  j = i / 7
  return units '%d ' % j, :weeks  if 8 > j
  j = i / 30
  return units '%d ' % j, :months  if 11 > j
  i /= 365.0
  return units '%.2f ' % i, :years  if 550 > i
  units '%d ' % i, :years
end

.units(val, unit) ⇒ Object



50
51
52
53
# File 'lib/pve/helper.rb', line 50

def units val, unit
  v = "#{val}\e[1;30m#{unit}\e[0m"
  V.new v, v.length - 11
end