Class: ImageOptim::Runner::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/image_optim/runner.rb

Overview

Collect and output results of optimization

Instance Method Summary collapse

Constructor Details

#initializeResults

Returns a new instance of Results.



16
17
18
19
20
# File 'lib/image_optim/runner.rb', line 16

def initialize
  @lines = []
  @original_size_sum = 0
  @optimized_size_sum = 0
end

Instance Method Details

#add(original, optimized) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/image_optim/runner.rb', line 22

def add(original, optimized)
  original_size = optimized ? optimized.original_size : original.size
  optimized_size = optimized ? optimized.size : original.size
  @lines << "#{size_percent(original_size, optimized_size)}  #{original}"
  @original_size_sum += original_size
  @optimized_size_sum += optimized_size
end


30
31
32
33
# File 'lib/image_optim/runner.rb', line 30

def print
  puts @lines
  puts "Total: #{size_percent(@original_size_sum, @optimized_size_sum)}"
end