Class: Arachni::OptBool

Inherits:
OptBase show all
Defined in:
lib/component_options.rb

Overview

Boolean option.

Constant Summary collapse

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

Instance Attribute Summary

Attributes inherited from OptBase

#default, #desc, #enums, #name, #owner, #required

Instance Method Summary collapse

Methods inherited from OptBase

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

Constructor Details

This class inherits a constructor from Arachni::OptBase

Instance Method Details

#is_false?(value) ⇒ Boolean

Returns:

  • (Boolean)


218
219
220
# File 'lib/component_options.rb', line 218

def is_false?(value)
    return !is_true?(value)
end

#is_true?(value) ⇒ Boolean

Returns:

  • (Boolean)


214
215
216
# File 'lib/component_options.rb', line 214

def is_true?(value)
    return normalize(value)
end

#normalize(value) ⇒ Object



206
207
208
209
210
211
212
# File 'lib/component_options.rb', line 206

def normalize(value)
    if(value.nil? or value.to_s.match(TrueRegex).nil?)
        false
    else
        true
    end
end

#typeObject



190
191
192
# File 'lib/component_options.rb', line 190

def type
    return 'bool'
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


194
195
196
197
198
199
200
201
202
203
204
# File 'lib/component_options.rb', line 194

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

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

    true
end