mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-25 03:10:49 +00:00
replace core extensions with util functions
This commit is contained in:
parent
37e8f67573
commit
099ef38fad
@ -1,6 +1,6 @@
|
|||||||
require_relative "install"
|
require_relative "install"
|
||||||
require_relative "errors"
|
require_relative "errors"
|
||||||
require_relative "core_extensions/string/snakecase"
|
require_relative "util"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module CBindings
|
module CBindings
|
||||||
@ -16,7 +16,7 @@ module Voicemeeter
|
|||||||
ffi_convention :stdcall
|
ffi_convention :stdcall
|
||||||
|
|
||||||
private_class_method def self.attach_function(c_name, args, returns)
|
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)
|
super(ruby_name, c_name, args, returns)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||||||
require_relative "core_extensions/string/camelcase"
|
require_relative "util"
|
||||||
|
|
||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module Errors
|
module Errors
|
||||||
@ -19,7 +19,7 @@ module Voicemeeter
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fn_name
|
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
|
end
|
||||||
end
|
end
|
||||||
|
19
lib/voicemeeter/util.rb
Normal file
19
lib/voicemeeter/util.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user