Class: Fastlane::Helper::LinkMap::FileHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::LinkMap::FileHelper
- Defined in:
- lib/fastlane/plugin/analyze_ios_linkmap/helper/analyze_ios_file_helper.rb
Class Method Summary collapse
Class Method Details
.file_size(file_path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fastlane/plugin/analyze_ios_linkmap/helper/analyze_ios_file_helper.rb', line 8 def self.file_size(file_path) return 0 unless File.exist?(file_path) base = File.basename(file_path) return 0 if ['.', '..'].include?(base) total = 0 if File.directory?(file_path) Dir.glob(File.('*', file_path)).each do |f| # pp f total += file_size(f) end else size = File.stat(file_path).size total += size end total end |
.format_size(bytes) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fastlane/plugin/analyze_ios_linkmap/helper/analyze_ios_file_helper.rb', line 28 def self.format_size(bytes) return '0 B' unless bytes return '0 B' if bytes.zero? k = 1024 suffix = %w[B KB MB GB TB PB EB ZB YB] i = (Math.log(bytes) / Math.log(k)).floor base = (k ** i).to_f num = (bytes / base).round(2) "#{num} " + suffix[i] end |