code cleanup in opt_int while we're here

bug/bundler_fix
Brent Cook 2017-08-05 02:22:04 -05:00
parent 47dc3772a7
commit b35d53bd02
1 changed files with 21 additions and 29 deletions

View File

@ -1,36 +1,28 @@
# -*- coding: binary -*-
module Msf
###
#
# Integer option.
#
###
class OptInt < OptBase
###
#
# Integer option.
#
###
class OptInt < OptBase
def type
return 'integer'
'integer'
end
def normalize(value)
if value.to_s.match(/^0x[a-fA-F\d]+$/)
if value.to_s.match?(/^0x[a-fA-F\d]+$/)
value.to_i(16)
elsif value.present?
value.to_i
else
nil
end
end
def valid?(value, check_empty: true)
return false if check_empty && empty_required_value?(value)
if value.present? and not value.to_s.match(/^0x[0-9a-fA-F]+$|^-?\d+$/)
return false
return false if value.present? && !value.to_s.match?(/^0x[0-9a-fA-F]+$|^-?\d+$/)
super
end
return super
end
end
end