Class: Msf::OptBool

Inherits:
OptBase show all
Defined in:
lib/msf/core/opt_bool.rb

Overview

Boolean option type

Constant Summary collapse

TRUE_REGEX =
/^(y|yes|t|1|true)$/i
ANY_REGEX =
/^(y|yes|n|no|t|f|0|1|true|false)$/i

Instance Attribute Summary

Attributes inherited from OptBase

#advanced, #aliases, #conditions, #default, #desc, #enums, #evasion, #fallbacks, #max_length, #name, #owner, #regex, #required

Instance Method Summary collapse

Methods inherited from OptBase

#advanced?, #display_value, #empty_required_value?, #evasion?, #invalid_value_length?, #required?, #type?, #validate_on_assignment?

Constructor Details

#initialize(in_name, attrs = [], default: false, **kwargs) ⇒ OptBool

This overrides default from ‘nil’ to ‘false’



10
11
12
13
# File 'lib/msf/core/opt_bool.rb', line 10

def initialize(in_name, attrs = [],
               default: false, **kwargs)
  super
end

Instance Method Details

#normalize(value) ⇒ Object



28
29
30
31
# File 'lib/msf/core/opt_bool.rb', line 28

def normalize(value)
  !(value.nil? ||
    value.to_s.match(TRUE_REGEX).nil?)
end

#typeObject



15
16
17
# File 'lib/msf/core/opt_bool.rb', line 15

def type
  return 'bool'
end

#valid?(value, check_empty: true) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/msf/core/opt_bool.rb', line 19

def valid?(value, check_empty: true)
  return false if check_empty && empty_required_value?(value)
  return true if value.nil? && !required?

  !(value.nil? ||
    value.to_s.empty? ||
    value.to_s.match(ANY_REGEX).nil?)
end