mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-12-04 15:40:49 +00:00
now using String refinement
This commit is contained in:
parent
5307bebea8
commit
f13501f1d8
@ -1,10 +1,11 @@
|
|||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
# Ruby bindings for the C-API functions
|
# Ruby bindings for the C-API functions
|
||||||
module CBindings
|
module CBindings
|
||||||
private
|
|
||||||
|
|
||||||
extend Logging
|
extend Logging
|
||||||
extend FFI::Library
|
extend FFI::Library
|
||||||
|
using Util::CoreExtensions
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
VM_PATH = Install.get_vmpath
|
VM_PATH = Install.get_vmpath
|
||||||
|
|
||||||
@ -14,7 +15,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_#{Util::String.snakecase(c_name.to_s.delete_prefix("VBVMR_"))}"
|
ruby_name = :"bind_#{c_name.to_s.delete_prefix("VBVMR_").snakecase}"
|
||||||
super(ruby_name, c_name, args, returns)
|
super(ruby_name, c_name, args, returns)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -52,8 +53,7 @@ module Voicemeeter
|
|||||||
|
|
||||||
def call(fn, *args, ok: [0], exp: nil)
|
def call(fn, *args, ok: [0], exp: nil)
|
||||||
to_cname = -> {
|
to_cname = -> {
|
||||||
"VBVMR_#{Util::String.camelcase(fn.to_s.delete_prefix("bind_"))
|
"VBVMR_#{fn.to_s.delete_prefix("bind_").camelcase.gsub(/(Button|Input|Output)/, '\1_')}"
|
||||||
.gsub(/(Button|Input|Output)/, '\1_')}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = send(fn, *args)
|
res = send(fn, *args)
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
module Voicemeeter
|
module Voicemeeter
|
||||||
module Util
|
module Util
|
||||||
module String
|
module CoreExtensions
|
||||||
def snakecase(s)
|
refine String do
|
||||||
s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
def snakecase
|
||||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||||
.tr("-", "_")
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||||
.gsub(/\s/, "_")
|
.tr("-", "_")
|
||||||
.gsub(/__+/, "_")
|
.gsub(/\s/, "_")
|
||||||
.downcase
|
.gsub(/__+/, "_")
|
||||||
end
|
.downcase
|
||||||
|
end
|
||||||
|
|
||||||
def camelcase(s)
|
def camelcase
|
||||||
s if s !~ /_/ && s =~ /[A-Z]+.*/
|
self if self !~ /_/ && self =~ /[A-Z]+.*/
|
||||||
s.split("_").map { |e| e.capitalize }.join
|
split("_").map(&:capitalize).join
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module_function :snakecase, :camelcase
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Cache
|
module Cache
|
||||||
|
Loading…
Reference in New Issue
Block a user