class ImageOptim::OptionDefinition
Hold information about an option
Attributes
default[R]
description[R]
name[R]
proc[R]
type[R]
Public Class Methods
new(name, default, type_or_description, description = nil, &proc)
click to toggle source
# File lib/image_optim/option_definition.rb, line 6 def initialize(name, default, type_or_description, description = nil, &proc) if type_or_description.is_a?(Class) type = type_or_description else type, description = default.class, type_or_description end @name = name.to_sym @description = description.to_s @default, @type, @proc = default, type, proc end
Public Instance Methods
default_description()
click to toggle source
Describe default value, returns string as is otherwise surrounds inspected value with backticks
# File lib/image_optim/option_definition.rb, line 34 def default_description default.is_a?(String) ? default : "`#{default.inspect}`" end
value(worker, options)
click to toggle source
Get value for worker from options
# File lib/image_optim/option_definition.rb, line 19 def value(worker, options) value = options.key?(name) ? options[name] : default if proc if proc.arity == 2 worker.instance_exec(value, self, &proc) else worker.instance_exec(value, &proc) end else value end end