Class: Integer
- Defined in:
- lib/rmtools/conversions/ip.rb,
lib/rmtools/conversions/int.rb
Instance Method Summary collapse
- #bytes(t = nil) ⇒ Object
- #from_ip ⇒ Object
- #gb ⇒ Object
- #kb ⇒ Object
- #mask_ip(val) ⇒ Object
- #mb ⇒ Object
- #to_ip ⇒ Object
- #to_timestr(t = nil) ⇒ Object
Instance Method Details
#bytes(t = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rmtools/conversions/int.rb', line 28 def bytes(t=nil) if t if :kb == t "%.2fKB"%[to_f/1024] elsif :mb == t "%.2fMB"%[to_f/1048576] elsif :gb == t "%.2fGB"%[to_f/1073741824] end elsif self < 1024 "#{self}B" elsif self < 1048576 "%.2fKB"%[to_f/1024] elsif self < 1073741824 "%.2fMB"%[to_f/1048576] else "%.2fGB"%[to_f/1073741824] end end |
#from_ip ⇒ Object
50 51 52 |
# File 'lib/rmtools/conversions/ip.rb', line 50 def from_ip self end |
#gb ⇒ Object
6 |
# File 'lib/rmtools/conversions/int.rb', line 6 def gb; self*1073741824 end |
#kb ⇒ Object
4 |
# File 'lib/rmtools/conversions/int.rb', line 4 def kb; self*1024 end |
#mask_ip(val) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/rmtools/conversions/ip.rb', line 58 def mask_ip(val) if val < 0 maskv = 32+val else maskv = val val = 32 - val end self - (self & 2**val - 1) end |
#mb ⇒ Object
5 |
# File 'lib/rmtools/conversions/int.rb', line 5 def mb; self*1048576 end |
#to_ip ⇒ Object
54 55 56 |
# File 'lib/rmtools/conversions/ip.rb', line 54 def to_ip "#{(self >> 24) & 0xff}.#{(self >> 16) & 0xff}.#{(self >> 8) & 0xff}.#{self & 0xff}" end |
#to_timestr(t = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rmtools/conversions/int.rb', line 8 def to_timestr(t=nil) if t if t.in [:minutes, :min, :m] "#{self/60} minutes" elsif t.in [:hours, :h] "#{self/3600} hours" elsif t.in [:days, :d] "#{self/86400} days" end elsif self < 60 "#{self} seconds" elsif self < 3600 "#{self/60} minutes" elsif self < 86400 "#{self/3600} hours" else "#{self/86400} days" end end |