Sha256: 3c3f477409f67c9180888c2d7fc508c15b865e75f7ff141051e0735b773323fe

Contents?: true

Size: 572 Bytes

Versions: 12

Compression:

Stored size: 572 Bytes

Contents

# frozen_string_literal: true

class ImageOptim
  # Denote ternary value (`true`/`false`/`nil`) for worker option
  class TrueFalseNil
    # Add handling of ternary value in OptionParser instance, maps `nil` and
    # `'nil'` to `nil`
    def self.add_to_option_parser(option_parser)
      completing = OptionParser.top.atype[TrueClass][0].merge('nil' => nil)
      option_parser.accept(self, completing){ |_arg, val| val }
    end

    # Convert everything truthy to `true`, leave `false` and `nil` as is
    def self.convert(value)
      value && true
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
image_optim-0.31.4 lib/image_optim/true_false_nil.rb
image_optim-0.31.3 lib/image_optim/true_false_nil.rb
image_optim-0.31.2 lib/image_optim/true_false_nil.rb
image_optim-0.31.1 lib/image_optim/true_false_nil.rb
image_optim-0.31.0 lib/image_optim/true_false_nil.rb
image_optim-0.30.0 lib/image_optim/true_false_nil.rb
image_optim-0.29.0 lib/image_optim/true_false_nil.rb
image_optim-0.28.0 lib/image_optim/true_false_nil.rb
image_optim-0.27.1 lib/image_optim/true_false_nil.rb
image_optim-0.27.0 lib/image_optim/true_false_nil.rb
image_optim-0.26.5 lib/image_optim/true_false_nil.rb
image_optim-0.26.4 lib/image_optim/true_false_nil.rb