vrobot4/source/common.rb

38 lines
1.0 KiB
Ruby
Raw Normal View History

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.
2017-08-11 15:16:16 -07:00
Version = "4.00".freeze
2017-08-11 19:40:43 -07:00
def self.debug=(set) @@debug = set end # Sets the current debug level.
def self.debug ( ) @@debug end # Gets the current debug level.
2017-08-11 19:40:43 -07:00
# Logs to the console.
#
# @param lv [Symbol]
# - If +:DEBUG+, this message will not be printed if the global debug
# level is less than 1.
# - If +:DEBUGV+, this message will not be printed if the global debug
# level is less than 2.
# @return [Boolean] true if the message was printed, false otherwise
def self.log lv, *text
2017-08-06 16:27:36 -07:00
if (lv != :DEBUG || @@debug >= 1) &&
(lv != :DEBUGV || @@debug >= 2)
puts "[" + lv.to_s.ljust(6) + "] " + text.join(" ")
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.
# @param str [String] the string to check
2017-08-11 15:16:16 -07:00
def self.is_num? str
/\A[-+]?[0-9]*\.?[0-9]+\Z/ === str
end
2017-08-11 19:40:43 -07:00
private
@@debug = 0
end
## EOF