2023-07-17 06:03:37 +01:00
|
|
|
module Voicemeeter
|
|
|
|
module Util
|
2023-07-17 14:13:08 +01:00
|
|
|
module String
|
|
|
|
def snakecase(string)
|
|
|
|
string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
|
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
|
|
.tr("-", "_")
|
|
|
|
.gsub(/\s/, "_")
|
|
|
|
.gsub(/__+/, "_")
|
|
|
|
.downcase
|
|
|
|
end
|
|
|
|
|
|
|
|
def camelcase(string)
|
|
|
|
string if string !~ /_/ && string =~ /[A-Z]+.*/
|
|
|
|
string.split("_").map { |e| e.capitalize }.join
|
|
|
|
end
|
2023-07-17 06:03:37 +01:00
|
|
|
|
2023-07-17 14:13:08 +01:00
|
|
|
module_function :snakecase, :camelcase
|
2023-07-17 06:03:37 +01:00
|
|
|
end
|
|
|
|
|
2023-07-17 14:13:08 +01:00
|
|
|
module Cache
|
|
|
|
def polling(func, **kwargs)
|
|
|
|
params = {
|
|
|
|
get: kwargs[:name],
|
|
|
|
get_buttonstatus: "mb_#{kwargs[:id]}_#{kwargs[:mode]}"
|
|
|
|
}
|
|
|
|
return cache.delete(params[func]) if cache.key? params[func]
|
|
|
|
|
|
|
|
clear_dirty if @sync
|
|
|
|
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
2023-07-17 06:03:37 +01:00
|
|
|
end
|
|
|
|
end
|