Class: Spriteful::Optimizer
- Inherits:
-
Object
- Object
- Spriteful::Optimizer
- 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
-
#enabled? ⇒ Boolean
Public: Returns true if any optimization can be executed of if the ‘optimize!` will be a no-op.
-
#initialize ⇒ Optimizer
constructor
Public: Initializes the Optimizer, checking for missing optimizers that should be ignored when optimizing the image.
-
#optimize!(path) ⇒ Object
Public: Optimizes and replaces the given path.
-
#optimizers ⇒ Object
Private: Gets a list of supported optimizers.
Constructor Details
#initialize ⇒ Optimizer
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() 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.
26 27 28 |
# File 'lib/spriteful/optimizer.rb', line 26 def enabled? .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 |
#optimizers ⇒ Object
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 |