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.


14
15
16
17
18
# File 'lib/image_optim/runner.rb', line 14

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

Instance Method Details

#add(original, optimized) ⇒ Object


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

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

28
29
30
31
# File 'lib/image_optim/runner.rb', line 28

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