Class: Measured
- Inherits:
-
Object
- Object
- Measured
- Defined in:
- lib/pve/helper.rb
Class Method Summary collapse
- .bytes1(v) ⇒ Object
- .bytes2(v) ⇒ Object (also: bytes)
- .seconds(i) ⇒ Object
Class Method Details
.bytes1(v) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pve/helper.rb', line 17 def bytes1 v v = v.to_f return "%d B" % v if 512 > v %w[KiB MiBy GiByt TiByte ExiByte PetiByte].each_with_index do |m| v /= 1024 #return "%.1f %s" % [v, m] if 10 > v #return "%d %s" % [v, m] if 512 > v return "%.1f %s" % [v, m] if 512 > v end "%d PetiByte" % v end |
.bytes2(v) ⇒ Object Also known as: bytes
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pve/helper.rb', line 29 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pve/helper.rb', line 43 def seconds i i = i.to_i return '·' if 0 == i return "%d s" % i if 90 > i i /= 60 return "%d mi" % i if 90 > i i /= 60 return "%d hou" % i if 36 > i i /= 24 return "%d days" % i if 14 > i j = i / 7 return "%d weeks" % j if 25 > j i /= 365 return "%.1f years" if 550 > i "%dy" % i end |