Class: ImageOptim::Runner
- Inherits:
-
Object
- Object
- ImageOptim::Runner
- Defined in:
- lib/image_optim/runner.rb,
lib/image_optim/runner/glob_helpers.rb,
lib/image_optim/runner/option_parser.rb
Overview
Handling optimization using image_optim binary
Defined Under Namespace
Modules: GlobHelpers Classes: BenchmarkResults, OptionParser, Results
Instance Method Summary collapse
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
-
#run!(args) ⇒ Object
rubocop:disable Naming/PredicateMethod.
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/image_optim/runner.rb', line 85 def initialize() = HashHelpers.deep_symbolise_keys() @recursive = .delete(:recursive) @progress = .delete(:show_progress) != false @exclude_dir_globs, @exclude_file_globs = %w[dir file].map do |type| glob = .delete(:"exclude_#{type}_glob") || '.*' GlobHelpers.(glob) end # --benchmark @benchmark = .delete(:benchmark) if @benchmark unless [:threads].nil? warning '--benchmark ignores --threads' [:threads] = 1 # for consistency end if [:timeout] warning '--benchmark ignores --timeout' end end @image_optim = ImageOptim.new() end |
Instance Method Details
#run!(args) ⇒ Object
rubocop:disable Naming/PredicateMethod
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/image_optim/runner.rb', line 109 def run!(args) # rubocop:disable Naming/PredicateMethod to_optimize = find_to_optimize(args) unless to_optimize.empty? if @benchmark benchmark_results = BenchmarkResults.new benchmark_images(to_optimize).each do |_original, rows| # rubocop:disable Style/HashEachMethods benchmark_results.add(rows) end benchmark_results.print else results = Results.new optimize_images!(to_optimize).each do |original, optimized| results.add(original, optimized) end results.print end end !@warnings end |