Class: Arachni::Component::Options::Base
- Defined in:
- lib/arachni/component/options/base.rb
Overview
The base class for all options.
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.
Instance Method Summary collapse
- #==(opt) ⇒ Object
-
#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 = []) ⇒ Base
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 ⇒ Object
-
#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 = []) ⇒ Base
57 58 59 60 61 62 63 |
# File 'lib/arachni/component/options/base.rb', line 57 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.
37 38 39 |
# File 'lib/arachni/component/options/base.rb', line 37 def default @default end |
#desc ⇒ Object
The description of the option.
32 33 34 |
# File 'lib/arachni/component/options/base.rb', line 32 def desc @desc end |
#enums ⇒ Object
The list of potential valid values
42 43 44 |
# File 'lib/arachni/component/options/base.rb', line 42 def enums @enums end |
#name ⇒ Object
The name of the option.
27 28 29 |
# File 'lib/arachni/component/options/base.rb', line 27 def name @name end |
Instance Method Details
#==(opt) ⇒ Object
119 120 121 |
# File 'lib/arachni/component/options/base.rb', line 119 def ==( opt ) to_h == opt.to_h end |
#empty_required_value?(value) ⇒ Boolean
Returns true if the value supplied is nil and it’s required to be a valid value
90 91 92 |
# File 'lib/arachni/component/options/base.rb', line 90 def empty_required_value?( value ) required? && value.nil? end |
#normalize(value) ⇒ Object
Normalizes the supplied value to conform with the type that the option is conveying.
98 99 100 |
# File 'lib/arachni/component/options/base.rb', line 98 def normalize( value ) value end |
#required? ⇒ Boolean
Returns true if this is a required option.
68 69 70 |
# File 'lib/arachni/component/options/base.rb', line 68 def required? @required end |
#to_h ⇒ Hash
Converts the Options object to hash
111 112 113 114 115 116 117 |
# File 'lib/arachni/component/options/base.rb', line 111 def to_h hash = {} self.instance_variables.each do |var| hash[var.to_s.gsub( /@/, '' )] = self.instance_variable_get( var ) end hash.merge( 'type' => type ) end |
#type ⇒ Object
102 103 104 |
# File 'lib/arachni/component/options/base.rb', line 102 def type 'abstract' end |
#type?(in_type) ⇒ Boolean
Returns true if the supplied type is equivalent to this option’s type.
75 76 77 |
# File 'lib/arachni/component/options/base.rb', line 75 def type?( in_type ) type == in_type end |
#valid?(value) ⇒ Boolean
If it’s required and the value is nil or empty, then it’s not valid.
82 83 84 |
# File 'lib/arachni/component/options/base.rb', line 82 def valid?( value ) ( required? && ( value.nil? || value.to_s.empty? ) ) ? false : true end |