Class: StorageGuardian::Report
- Inherits:
-
Object
- Object
- StorageGuardian::Report
- Defined in:
- lib/storage_guardian/report.rb
Instance Attribute Summary collapse
-
#bloat ⇒ Object
readonly
Returns the value of attribute bloat.
-
#cold ⇒ Object
readonly
Returns the value of attribute cold.
-
#duplicates ⇒ Object
readonly
Returns the value of attribute duplicates.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #duplicate_size ⇒ Object
-
#initialize(root, entries, duplicates, bloat, cold) ⇒ Report
constructor
A new instance of Report.
- #summary ⇒ Object
- #to_s ⇒ Object
- #total_size ⇒ Object
Constructor Details
#initialize(root, entries, duplicates, bloat, cold) ⇒ Report
Returns a new instance of Report.
7 8 9 10 11 12 13 |
# File 'lib/storage_guardian/report.rb', line 7 def initialize(root, entries, duplicates, bloat, cold) @root = root @entries = entries @duplicates = duplicates @bloat = bloat @cold = cold end |
Instance Attribute Details
#bloat ⇒ Object (readonly)
Returns the value of attribute bloat.
5 6 7 |
# File 'lib/storage_guardian/report.rb', line 5 def bloat @bloat end |
#cold ⇒ Object (readonly)
Returns the value of attribute cold.
5 6 7 |
# File 'lib/storage_guardian/report.rb', line 5 def cold @cold end |
#duplicates ⇒ Object (readonly)
Returns the value of attribute duplicates.
5 6 7 |
# File 'lib/storage_guardian/report.rb', line 5 def duplicates @duplicates end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
5 6 7 |
# File 'lib/storage_guardian/report.rb', line 5 def entries @entries end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/storage_guardian/report.rb', line 5 def root @root end |
Instance Method Details
#duplicate_size ⇒ Object
19 20 21 |
# File 'lib/storage_guardian/report.rb', line 19 def duplicate_size @duplicates.sum { |group| group.sum(&:size) - group.first.size } end |
#summary ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/storage_guardian/report.rb', line 23 def summary { total_files: @entries.size, total_size_mb: (total_size / 1024.0 / 1024.0).round(2), duplicate_groups: @duplicates.size, duplicate_size_mb: (duplicate_size / 1024.0 / 1024.0).round(2), bloat_findings: @bloat.size, cold_files: @cold.size } end |
#to_s ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/storage_guardian/report.rb', line 34 def to_s lines = [] lines << "=== Storage Guardian Report ===" lines << "Root: #{@root}" s = summary lines << "Files: #{s[:total_files]} | Size: #{s[:total_size_mb]}MB" lines << "Duplicates: #{s[:duplicate_groups]} groups (#{s[:duplicate_size_mb]}MB wasted)" lines << "Bloat findings: #{s[:bloat_findings]}" lines << "Cold files: #{s[:cold_files]}" lines << "" if @duplicates.any? lines << "--- Duplicates ---" @duplicates.each do |group| lines << " #{group.size} copies: #{group.map(&:path).join(', ')}" end end if @bloat.any? lines << "--- Bloat ---" @bloat.each { |b| lines << " [#{b[:severity].upcase}] #{b[:message]}" } end if @cold.any? lines << "--- Cold Files (#{@cold.size}) ---" @cold.first(5).each { |c| lines << " #{c[:message]}" } lines << " ... and #{@cold.size - 5} more" if @cold.size > 5 end lines.join("\n") end |
#total_size ⇒ Object
15 16 17 |
# File 'lib/storage_guardian/report.rb', line 15 def total_size @entries.sum(&:size) end |