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