Sha256: 09df644d85abc272ced736e7add3f58c47b5888bd1a047078195c26da8cefb8b

Contents?: true

Size: 832 Bytes

Versions: 10

Compression:

Stored size: 832 Bytes

Contents

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)
        value = yield(value) if block_given?
      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 "unknown options #{options.inspect} for #{self}"
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
image_optim-0.5.0 lib/image_optim/option_helpers.rb
image_optim-0.4.2 lib/image_optim/option_helpers.rb
image_optim-0.4.1 lib/image_optim/option_helpers.rb
image_optim-0.4.0 lib/image_optim/option_helpers.rb
image_optim-0.3.2 lib/image_optim/option_helpers.rb
image_optim-0.3.1 lib/image_optim/option_helpers.rb
image_optim-0.3.0 lib/image_optim/option_helpers.rb
image_optim-0.2.1 lib/image_optim/option_helpers.rb
image_optim-0.2.0 lib/image_optim/option_helpers.rb
image_optim-0.1.0 lib/image_optim/option_helpers.rb