Class: Arachni::Component::Options::Bool

Inherits:
Base show all
Defined in:
lib/arachni/component/options/bool.rb

Overview

Boolean option.

Constant Summary collapse

TRUE_REGEX =
/^(y|yes|t|1|true|on)$/i

Instance Attribute Summary

Attributes inherited from Base

#default, #desc, #enums, #name

Instance Method Summary collapse

Methods inherited from Base

#==, #empty_required_value?, #initialize, #required?, #to_h, #type?

Constructor Details

This class inherits a constructor from Arachni::Component::Options::Base

Instance Method Details

#false?(value) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/arachni/component/options/bool.rb', line 52

def false?( value )
    !true?( value )
end

#normalize(value) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/arachni/component/options/bool.rb', line 40

def normalize( value )
    if value.nil? || value.to_s.match( TRUE_REGEX ).nil?
        false
    else
        true
    end
end

#true?(value) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/arachni/component/options/bool.rb', line 48

def true?( value )
    normalize( value )
end

#typeObject



25
26
27
# File 'lib/arachni/component/options/bool.rb', line 25

def type
    'bool'
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
# File 'lib/arachni/component/options/bool.rb', line 29

def valid?( value )
    return false if empty_required_value?(value)

    if value && !value.to_s.empty? &&
        !value.to_s.match( /^(y|yes|n|no|t|f|0|1|true|false|on)$/i )
        return false
    end

    true
end