now using String refinement

This commit is contained in:
onyx-and-iris 2023-08-29 22:56:40 +01:00
parent 5307bebea8
commit f13501f1d8
2 changed files with 19 additions and 19 deletions

View File

@ -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)

View File

@ -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