vrobot4/source/common.rb

50 lines
1.3 KiB
Ruby
Raw Normal View History

2019-02-23 20:46:40 -08:00
require 'zlib'
2017-08-11 19:40:43 -07:00
# Module for the main vrobot4 program and global info.
module Vrobot4
2017-08-11 19:40:43 -07:00
# The current program version.
2019-02-23 20:46:40 -08:00
Version = "4.01".freeze
2019-02-23 20:46:40 -08:00
# Sets the current debug level.
# @param set [Integer] the debug level
# @return [void]
def self.set_debug set
@@debug = set
end
2017-08-11 19:40:43 -07:00
# Logs to the console.
#
2019-02-23 20:46:40 -08:00
# @param lv [Symbol] the log level
# [+:INFO+] This message will always be printed.
# [+:DEBUG+] This message will not be printed if the global debug level is
# less than 1.
# [+:DEBUGV+] This message will not be printed if the global debug level is
# less than 2.
2017-08-11 19:40:43 -07:00
# @return [Boolean] true if the message was printed, false otherwise
2019-02-23 20:46:40 -08:00
def self.log lv, text
2017-08-06 16:27:36 -07:00
if (lv != :DEBUG || @@debug >= 1) &&
(lv != :DEBUGV || @@debug >= 2)
2019-02-23 20:46:40 -08:00
puts "[#{lv.to_s.ljust 6}] #{text}"
2017-08-11 15:16:16 -07:00
true
else
false
end
end
2017-08-11 19:40:43 -07:00
# Checks if the argument +s+ is a numeric string.
2019-02-23 20:46:40 -08:00
# @param s [String] the string to check
# @return [Boolean] true if +s+ is a numeric string, false otherwise
def self.is_num? s
/\A[-+]?[0-9]*\.?[0-9]+\Z/ === s
end
2017-08-11 19:40:43 -07:00
2019-02-23 20:46:40 -08:00
# Does a stable hash on +s+.
# @param s [String] the string to hash
# @return [Integer]
def self.hash_str s
Zlib.crc32 s
end
end
## EOF