Class: ImageOptim::Runner

Inherits:
Object
  • Object
show all
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: OptionParser, Results

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.


46
47
48
49
50
51
52
53
54
55
# File 'lib/image_optim/runner.rb', line 46

def initialize(options)
  options = HashHelpers.deep_symbolise_keys(options)
  @recursive = options.delete(:recursive)
  @progress = options.delete(:show_progress) != false
  @exclude_dir_globs, @exclude_file_globs = %w[dir file].map do |type|
    glob = options.delete(:"exclude_#{type}_glob") || '.*'
    GlobHelpers.expand_braces(glob)
  end
  @image_optim = ImageOptim.new(options)
end

Instance Method Details

#run!(args) ⇒ Object


57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/image_optim/runner.rb', line 57

def run!(args)
  to_optimize = find_to_optimize(args)
  unless to_optimize.empty?
    results = Results.new

    optimize_images!(to_optimize).each do |original, optimized|
      results.add(original, optimized)
    end

    results.print
  end

  !@warnings
end