Class: ImageOptim::OptionDefinition
- Inherits:
-
Object
- Object
- ImageOptim::OptionDefinition
- Defined in:
- lib/image_optim/option_definition.rb
Overview
Hold information about an option
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#default_description ⇒ Object
Describe default value, returns string as is otherwise surrounds inspected value with backticks.
-
#initialize(name, default, type_or_description, description = nil, &proc) ⇒ OptionDefinition
constructor
A new instance of OptionDefinition.
-
#value(worker, options) ⇒ Object
Get value for worker from options.
Constructor Details
#initialize(name, default, type_or_description, description = nil, &proc) ⇒ OptionDefinition
Returns a new instance of OptionDefinition.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/image_optim/option_definition.rb', line 8 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 |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/image_optim/option_definition.rb', line 6 def default @default end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/image_optim/option_definition.rb', line 6 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/image_optim/option_definition.rb', line 6 def name @name end |
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
6 7 8 |
# File 'lib/image_optim/option_definition.rb', line 6 def proc @proc end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/image_optim/option_definition.rb', line 6 def type @type end |
Instance Method Details
#default_description ⇒ Object
Describe default value, returns string as is otherwise surrounds inspected value with backticks
36 37 38 |
# File 'lib/image_optim/option_definition.rb', line 36 def default_description default.is_a?(String) ? default : "`#{default.inspect}`" end |
#value(worker, options) ⇒ Object
Get value for worker from options
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/image_optim/option_definition.rb', line 21 def value(worker, ) value = .key?(name) ? [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 |