Class: Arachni::Component::Options::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/arachni/component/options/base.rb

Overview

The base class for all options.

Direct Known Subclasses

Address, Bool, Enum, Float, Int, Path, Port, String, URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attrs = []) ⇒ Base

Initializes a named option with the supplied attribute array. The array is composed of three values.

attrs = required (boolean type) attrs = description (string) attrs = default value attrs = possible enum values

Parameters:

  • name (String)

    the name of the options

  • attrs (Array) (defaults to: [])

    option attributes



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

#defaultObject

The default value of the option.



37
38
39
# File 'lib/arachni/component/options/base.rb', line 37

def default
  @default
end

#descObject

The description of the option.



32
33
34
# File 'lib/arachni/component/options/base.rb', line 32

def desc
  @desc
end

#enumsObject

The list of potential valid values



42
43
44
# File 'lib/arachni/component/options/base.rb', line 42

def enums
  @enums
end

#nameObject

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

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


68
69
70
# File 'lib/arachni/component/options/base.rb', line 68

def required?
    @required
end

#to_hHash

Converts the Options object to hash

Returns:



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

#typeObject



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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