voicemeeter-rb/lib/voicemeeter/util.rb

36 lines
820 B
Ruby
Raw Normal View History

module Voicemeeter
module Util
2023-08-29 22:56:40 +01:00
module CoreExtensions
refine String do
def snakecase
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
.tr("-", "_")
.gsub(/\s/, "_")
.gsub(/__+/, "_")
.downcase
end
2023-08-29 22:56:40 +01:00
def camelcase
self if self !~ /_/ && self =~ /[A-Z]+.*/
split("_").map(&:capitalize).join
end
end
end
module Cache
2023-07-26 14:12:47 +01:00
def get(name, is_string = false)
return cache.delete(name) if cache.key? name
clear_dirty if @sync
2023-07-26 14:12:47 +01:00
super
end
2023-07-26 14:12:47 +01:00
def get_buttonstatus(id, mode)
return cache.delete("mb_#{id}_#{mode}") if cache.key? "mb_#{id}_#{mode}"
clear_dirty if @sync
super
end
end
end
end