Class: Spriteful::Optimizer

Inherits:
Object
  • Object
show all
Defined in:
lib/spriteful/optimizer.rb

Overview

Internal: Wrapper class for the ‘ImageOptim` gem that can optimize PNG images and won’t crash if no PNG optimizer is presented.

Instance Method Summary collapse

Constructor Details

#initializeOptimizer

Public: Initializes the Optimizer, checking for missing optimizers that should be ignored when optimizing the image.



10
11
12
13
# File 'lib/spriteful/optimizer.rb', line 10

def initialize
  @workers = ImageOptim::Worker.klasses.map { |k| k.name.split('::').last.downcase }
  @optimizer = ImageOptim.new(optimization_options)
end

Instance Method Details

#enabled?Boolean

Public: Returns true if any optimization can be executed of if the ‘optimize!` will be a no-op.

Returns true or false.

Returns:

  • (Boolean)


26
27
28
# File 'lib/spriteful/optimizer.rb', line 26

def enabled?
  optimization_options.values.any?
end

#optimize!(path) ⇒ Object

Public: Optimizes and replaces the given path.

Returns nothing.



18
19
20
# File 'lib/spriteful/optimizer.rb', line 18

def optimize!(path)
  @optimizer.optimize_image!(path)
end

#optimizersObject

Private: Gets a list of supported optimizers.



31
32
33
# File 'lib/spriteful/optimizer.rb', line 31

def optimizers
  @workers.select { |w| supported_worker?(w) }
end