Module: Martilla::Backup::Utilities
- Included in:
- Martilla::Backup
- Defined in:
- lib/martilla/utilities.rb
Instance Method Summary collapse
- #duration_format(seconds) ⇒ Object
- #formatted_file_size ⇒ Object
- #s_to_h(seconds) ⇒ Object
- #s_to_m(seconds) ⇒ Object
Instance Method Details
#duration_format(seconds) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/martilla/utilities.rb', line 4 def duration_format(seconds) case seconds.to_i when 0..59 # 22s "#{seconds.to_i}s" when 60..3599 # 18m 19s "#{s_to_m(seconds).to_i}m #{(seconds % 60).to_i}s" else # 7h 9m 51s "#{s_to_h(seconds).to_i}h #{s_to_m(seconds).to_i}m #{(seconds % 60).to_i}s" end end |
#formatted_file_size ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/martilla/utilities.rb', line 26 def formatted_file_size return if @file_size.nil? if @file_size <= 799_999 compressed_file_size = @file_size / 2**10 formatted_size = '%.2f' % compressed_file_size "#{formatted_size} KB" elsif @file_size <= 799_999_999 compressed_file_size = @file_size / 2**20 formatted_size = '%.2f' % compressed_file_size "#{formatted_size} MB" else compressed_file_size = @file_size / 2**30 formatted_size = '%.2f' % compressed_file_size "#{formatted_size} GB" end end |
#s_to_h(seconds) ⇒ Object
22 23 24 |
# File 'lib/martilla/utilities.rb', line 22 def s_to_h(seconds) (seconds / 3600) % 3600 end |
#s_to_m(seconds) ⇒ Object
18 19 20 |
# File 'lib/martilla/utilities.rb', line 18 def s_to_m(seconds) (seconds / 60) % 60 end |