summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-08-23 08:08:09 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-08-23 08:08:09 +0000
commit6fde22f9311f0e009766bd1f190786c63a84a7b4 (patch)
tree5c75c775c058144846cff061aebf6a8ef3ae0104 /lib
parent2905d1791ccbe3a00669971d7d5e690643827751 (diff)
config: allow migration from/to Boolean/IntegerValues
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/config.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index de7b29b7..eb342f7c 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -114,15 +114,36 @@ module Irc
def parse(string)
return true if string == "true"
return false if string == "false"
- raise ArgumentError, "#{string} does not match either 'true' or 'false'"
+ if string =~ /^-?\d+$/
+ return string.to_i != 0
+ end
+ raise ArgumentError, "#{string} does not match either 'true' or 'false', and it's not an integer either"
+ end
+ def get
+ r = super
+ if r.kind_of?(Integer)
+ return r != 0
+ else
+ return r
+ end
end
end
class BotConfigIntegerValue < BotConfigValue
def parse(string)
+ return 1 if string == "true"
+ return 0 if string == "false"
raise ArgumentError, "not an integer: #{string}" unless string =~ /^-?\d+$/
string.to_i
end
+ def get
+ r = super
+ if r.kind_of?(Integer)
+ return r
+ else
+ return r ? 1 : 0
+ end
+ end
end
class BotConfigFloatValue < BotConfigValue