replace core extensions with util functions

This commit is contained in:
onyx-and-iris 2023-07-17 06:03:37 +01:00
parent 37e8f67573
commit 099ef38fad
5 changed files with 23 additions and 36 deletions

View File

@ -1,6 +1,6 @@
require_relative "install"
require_relative "errors"
require_relative "core_extensions/string/snakecase"
require_relative "util"
module Voicemeeter
module CBindings
@ -16,7 +16,7 @@ module Voicemeeter
ffi_convention :stdcall
private_class_method def self.attach_function(c_name, args, returns)
ruby_name = "bind_#{c_name.to_s.delete_prefix("VBVMR_").snakecase}".to_sym
ruby_name = "bind_#{Util.snakecase(c_name.to_s.delete_prefix("VBVMR_"))}".to_sym
super(ruby_name, c_name, args, returns)
end

View File

@ -1,14 +0,0 @@
module Voicemeeter
module Ext
module String
module CamelCase
class ::String
def camelcase
self if self !~ /_/ && self =~ /[A-Z]+.*/
split("_").map { |e| e.capitalize }.join
end
end
end
end
end
end

View File

@ -1,18 +0,0 @@
module Voicemeeter
module Ext
module String
module SnakeCase
class ::String
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
end
end
end
end
end

View File

@ -1,4 +1,4 @@
require_relative "core_extensions/string/camelcase"
require_relative "util"
module Voicemeeter
module Errors
@ -19,7 +19,7 @@ module Voicemeeter
end
def fn_name
"VBVMR_#{@ruby_name.to_s.delete_prefix("bind_").camelcase.sub("macro_button", "macrobutton")}"
"VBVMR_#{Util.camelcase(@ruby_name.to_s.delete_prefix("bind_")).sub("macro_button", "macrobutton")}"
end
end
end

19
lib/voicemeeter/util.rb Normal file
View File

@ -0,0 +1,19 @@
module Voicemeeter
module Util
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
module_function :snakecase, :camelcase
end
end