Class: Wpcap::Backup
- Inherits:
-
Object
- Object
- Wpcap::Backup
- Defined in:
- lib/wpcap/backup.rb
Constant Summary collapse
- PREFIX =
%W(TiB GiB MiB KiB B).freeze
Class Method Summary collapse
Instance Method Summary collapse
- #as_size(s) ⇒ Object
- #at ⇒ Object
-
#initialize(ls) ⇒ Backup
constructor
A new instance of Backup.
- #name ⇒ Object
- #size ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(ls) ⇒ Backup
Returns a new instance of Backup.
3 4 5 |
# File 'lib/wpcap/backup.rb', line 3 def initialize(ls) @data ||= ls.split(" ") end |
Class Method Details
Instance Method Details
#as_size(s) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/wpcap/backup.rb', line 36 def as_size( s ) s = s.to_f i = PREFIX.length - 1 while s > 512 && i > 0 i -= 1 s /= 1024 end ((s > 9 || s.modulo(1) < 0.1 ? '%d' : '%.1f') % s) + ' ' + PREFIX[i] end |
#at ⇒ Object
20 21 22 |
# File 'lib/wpcap/backup.rb', line 20 def at Time.at("#{name.chomp(".sql.bz2").split(".")[1]}.#{name.chomp(".sql.bz2").split(".")[2]}".to_f).strftime("%c") end |
#name ⇒ Object
7 8 9 |
# File 'lib/wpcap/backup.rb', line 7 def name @name ||= @data[8] end |
#size ⇒ Object
16 17 18 |
# File 'lib/wpcap/backup.rb', line 16 def size as_size( @data[4] ) end |
#type ⇒ Object
11 12 13 14 |
# File 'lib/wpcap/backup.rb', line 11 def type type = name.split(".")[0] @type ||= "#{type} " end |