Class: Glyphs::PruneReport

Inherits:
Object
  • Object
show all
Defined in:
lib/glyphs/prune_report.rb

Overview

The result of an IconPruner run: per-(library, variant) counts, a sample of deleted names, and a human-readable summary. Value object, no side effects.

Defined Under Namespace

Classes: LibraryStat

Constant Summary collapse

SAMPLE_LIMIT =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stats:, deleted_names:, dry_run:) ⇒ PruneReport

Returns a new instance of PruneReport.



13
14
15
16
17
# File 'lib/glyphs/prune_report.rb', line 13

def initialize(stats:, deleted_names:, dry_run:)
  @stats = stats
  @deleted_names = deleted_names
  @dry_run = dry_run
end

Instance Attribute Details

#deleted_namesObject (readonly)

Returns the value of attribute deleted_names.



11
12
13
# File 'lib/glyphs/prune_report.rb', line 11

def deleted_names
  @deleted_names
end

#dry_runObject (readonly)

Returns the value of attribute dry_run.



11
12
13
# File 'lib/glyphs/prune_report.rb', line 11

def dry_run
  @dry_run
end

#statsObject (readonly)

Returns the value of attribute stats.



11
12
13
# File 'lib/glyphs/prune_report.rb', line 11

def stats
  @stats
end

Instance Method Details

#bytes_freedObject



21
# File 'lib/glyphs/prune_report.rb', line 21

def bytes_freed = stats.sum(&:bytes_freed)

#deleted_countObject



19
# File 'lib/glyphs/prune_report.rb', line 19

def deleted_count = stats.sum(&:deleted)

#kept_countObject



20
# File 'lib/glyphs/prune_report.rb', line 20

def kept_count = stats.sum(&:kept)

#to_sObject



23
24
25
26
27
28
# File 'lib/glyphs/prune_report.rb', line 23

def to_s
  lines = [headline, *stat_lines]
  lines << sample_line if deleted_names.any?
  lines << "  Re-run with PRUNE=1 GLYPHS_PRUNE_ICONS=1 to delete." if dry_run
  lines.join("\n")
end