Sha256: 2899e856fcd74c371a6bb06c7c553bcde94ff6bd3ae10efbf0774d763aede295

Contents?: true

Size: 891 Bytes

Versions: 4

Compression:

Stored size: 891 Bytes

Contents

require 'image_optim'

class ImageOptim
  module OptionHelpers
    # Remove option from hash and run through block or return default
    def get_option!(options, name, default)
      value = default
      if options.has_key?(name)
        value = options.delete(name)
      end
      if block_given?
        value = yield(value)
      end
      instance_variable_set("@#{name}", value)
    end

    # Ensure number is in range
    def limit_with_range(number, range)
      if range.include?(number)
        number
      elsif number < range.first
        range.first
      elsif range.exclude_end?
        range.last - 1
      else
        range.last
      end
    end

    # Raise unless all options are deleted
    def assert_options_empty!(options)
      unless options.empty?
        raise ConfigurationError, "unknown options #{options.inspect} for #{self}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
image_optim-0.7.3 lib/image_optim/option_helpers.rb
image_optim-0.7.2 lib/image_optim/option_helpers.rb
image_optim-0.7.1 lib/image_optim/option_helpers.rb
image_optim-0.7.0 lib/image_optim/option_helpers.rb