Class: Arachni::OptBase
Overview
The base class for all options.
Direct Known Subclasses
OptAddress, OptBool, OptEnum, OptFloat, OptInt, OptPath, OptPort, OptString, OptUrl
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
The default value of the option.
-
#desc ⇒ Object
readonly
The description of the option.
-
#enums ⇒ Object
The list of potential valid values.
-
#name ⇒ Object
The name of the option.
-
#owner ⇒ Object
The component that owns this option.
-
#required ⇒ Object
readonly
Whether or not the option is required.
Instance Method Summary collapse
-
#empty_required_value?(value) ⇒ Boolean
Returns true if the value supplied is nil and it’s required to be a valid value.
-
#initialize(name, attrs = []) ⇒ OptBase
constructor
Initializes a named option with the supplied attribute array.
-
#normalize(value) ⇒ Object
Normalizes the supplied value to conform with the type that the option is conveying.
-
#required? ⇒ Boolean
Returns true if this is a required option.
-
#to_h ⇒ Hash
Converts the Options object to hash.
-
#type?(in_type) ⇒ Boolean
Returns true if the supplied type is equivalent to this option’s type.
-
#valid?(value) ⇒ Boolean
If it’s required and the value is nil or empty, then it’s not valid.
Constructor Details
#initialize(name, attrs = []) ⇒ OptBase
74 75 76 77 78 79 80 |
# File 'lib/arachni/component_options.rb', line 74 def initialize( name, attrs = [] ) @name = name @required = attrs[0] || false @desc = attrs[1] @default = attrs[2] @enums = [ *(attrs[3]) ].map { |x| x.to_s } end |
Instance Attribute Details
#default ⇒ Object
The default value of the option.
44 45 46 |
# File 'lib/arachni/component_options.rb', line 44 def default @default end |
#desc ⇒ Object
The description of the option.
39 40 41 |
# File 'lib/arachni/component_options.rb', line 39 def desc @desc end |
#enums ⇒ Object
The list of potential valid values
59 60 61 |
# File 'lib/arachni/component_options.rb', line 59 def enums @enums end |
#name ⇒ Object
The name of the option.
29 30 31 |
# File 'lib/arachni/component_options.rb', line 29 def name @name end |
#owner ⇒ Object
The component that owns this option.
54 55 56 |
# File 'lib/arachni/component_options.rb', line 54 def owner @owner end |
#required ⇒ Object
Whether or not the option is required.
34 35 36 |
# File 'lib/arachni/component_options.rb', line 34 def required @required end |
Instance Method Details
#empty_required_value?(value) ⇒ Boolean
Returns true if the value supplied is nil and it’s required to be a valid value
107 108 109 |
# File 'lib/arachni/component_options.rb', line 107 def empty_required_value?( value ) return ( required? && value.nil? ) end |
#normalize(value) ⇒ Object
Normalizes the supplied value to conform with the type that the option is conveying.
115 116 117 |
# File 'lib/arachni/component_options.rb', line 115 def normalize( value ) value end |
#required? ⇒ Boolean
Returns true if this is a required option.
85 86 87 |
# File 'lib/arachni/component_options.rb', line 85 def required? return required end |
#to_h ⇒ Hash
Converts the Options object to hash
124 125 126 127 128 129 130 131 |
# File 'lib/arachni/component_options.rb', line 124 def to_h hash = Hash.new self.instance_variables.each { |var| hash[var.to_s.gsub( /@/, '' )] = self.instance_variable_get( var ) } return hash.merge( 'type' => type ) end |
#type?(in_type) ⇒ Boolean
Returns true if the supplied type is equivalent to this option’s type.
92 93 94 |
# File 'lib/arachni/component_options.rb', line 92 def type?( in_type ) return (type == in_type) end |
#valid?(value) ⇒ Boolean
If it’s required and the value is nil or empty, then it’s not valid.
99 100 101 |
# File 'lib/arachni/component_options.rb', line 99 def valid?( value ) return ( required? && ( value == nil || value.to_s.empty? ) ) ? false : true end |