Class: ImageOptim::Worker
- Inherits:
-
Object
- Object
- ImageOptim::Worker
- Includes:
- OptionHelpers
- Defined in:
- lib/image_optim/worker.rb,
lib/image_optim/worker/advpng.rb,
lib/image_optim/worker/pngout.rb,
lib/image_optim/worker/optipng.rb,
lib/image_optim/worker/gifsicle.rb,
lib/image_optim/worker/jpegtran.rb,
lib/image_optim/worker/pngcrush.rb,
lib/image_optim/worker/jpegoptim.rb
Defined Under Namespace
Classes: Advpng, Gifsicle, Jpegoptim, Jpegtran, Optipng, Pngcrush, Pngout
Class Method Summary collapse
-
.bin_sym ⇒ Object
Underscored class name symbol.
-
.inherited(base) ⇒ Object
Remember all classes inheriting from this one.
-
.klasses ⇒ Object
List of available workers.
- .option(name, default, type, description = nil, &proc) ⇒ Object
- .option_definitions ⇒ Object
Instance Method Summary collapse
-
#image_formats ⇒ Object
List of formats which worker can optimize.
-
#initialize(image_optim, options = {}) ⇒ Worker
constructor
Configure (raises on extra options).
-
#optimized?(src, dst) ⇒ Boolean
Check if operation resulted in optimized file.
-
#run_order ⇒ Object
Ordering in list of workers.
Methods included from OptionHelpers
#assert_options_empty!, #get_option!, limit_with_range
Constructor Details
#initialize(image_optim, options = {}) ⇒ Worker
Configure (raises on extra options)
38 39 40 41 42 43 44 |
# File 'lib/image_optim/worker.rb', line 38 def initialize(image_optim, = {}) @image_optim = image_optim self.class.option_definitions.each do |option_definition| get_option!(, option_definition.name, option_definition.default, &option_definition.proc) end () end |
Class Method Details
.bin_sym ⇒ Object
Underscored class name symbol
21 22 23 |
# File 'lib/image_optim/worker.rb', line 21 def bin_sym @underscored_name ||= name.split('::').last.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.to_sym end |
.inherited(base) ⇒ Object
Remember all classes inheriting from this one
16 17 18 |
# File 'lib/image_optim/worker.rb', line 16 def inherited(base) klasses << base end |
.klasses ⇒ Object
List of available workers
11 12 13 |
# File 'lib/image_optim/worker.rb', line 11 def klasses @klasses ||= [] end |
.option(name, default, type, description = nil, &proc) ⇒ Object
29 30 31 32 |
# File 'lib/image_optim/worker.rb', line 29 def option(name, default, type, description = nil, &proc) attr_reader name option_definitions << OptionDefinition.new(name, default, type, description, &proc) end |
.option_definitions ⇒ Object
25 26 27 |
# File 'lib/image_optim/worker.rb', line 25 def option_definitions @option_definitions ||= [] end |
Instance Method Details
#image_formats ⇒ Object
List of formats which worker can optimize
47 48 49 50 |
# File 'lib/image_optim/worker.rb', line 47 def image_formats format_from_name = self.class.name.downcase[/gif|jpeg|png/] format_from_name ? [format_from_name.to_sym] : [] end |
#optimized?(src, dst) ⇒ Boolean
Check if operation resulted in optimized file
58 59 60 |
# File 'lib/image_optim/worker.rb', line 58 def optimized?(src, dst) dst.size? && dst.size < src.size end |
#run_order ⇒ Object
Ordering in list of workers
53 54 55 |
# File 'lib/image_optim/worker.rb', line 53 def run_order 0 end |