From 4c4746fe8a5e3f31b21d51ee332489b41ac5194e Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Tue, 29 Aug 2023 22:55:11 +0100 Subject: [PATCH] now using String refinement Events Director module renamed patch bump --- lib/obsws/event.rb | 8 ++++---- lib/obsws/mixin.rb | 7 ++++--- lib/obsws/util.rb | 19 ++++++++++--------- lib/obsws/version.rb | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/obsws/event.rb b/lib/obsws/event.rb index f14f650..36e9ced 100644 --- a/lib/obsws/event.rb +++ b/lib/obsws/event.rb @@ -28,8 +28,8 @@ module OBSWS ALL = LOW_VOLUME | HIGH_VOLUME end - module EventDirector - include Util::String + module Director + using Util::CoreExtensions def observers @observers ||= {} @@ -50,13 +50,13 @@ module OBSWS end def fire(event, data) - observers[snakecase(event).to_sym]&.each { |block| data.empty? ? block.call : block.call(data) } + observers[event.snakecase.to_sym]&.each { |block| data.empty? ? block.call : block.call(data) } end end class Client include Logging - include EventDirector + include Events::Director include Mixin::TearDown include Mixin::OPCodes diff --git a/lib/obsws/mixin.rb b/lib/obsws/mixin.rb index d26bf58..af6c730 100644 --- a/lib/obsws/mixin.rb +++ b/lib/obsws/mixin.rb @@ -1,16 +1,17 @@ module OBSWS module Mixin module Meta - include Util::String + using Util::CoreExtensions def make_field_methods(*params) params.each do |param| - define_singleton_method(snakecase(param.to_s)) { @resp[param] } + define_singleton_method(param.to_s.snakecase) { @resp[param] } end end end class MetaObject + using Util::CoreExtensions include Mixin::Meta def initialize(resp, fields) @@ -21,7 +22,7 @@ module OBSWS def empty? = @fields.empty? - def attrs = @fields.map { |f| snakecase(f.to_s) } + def attrs = @fields.map { |f| f.to_s.snakecase } end # Represents a request response object diff --git a/lib/obsws/util.rb b/lib/obsws/util.rb index 74fb1f1..dc1a5a5 100644 --- a/lib/obsws/util.rb +++ b/lib/obsws/util.rb @@ -1,15 +1,16 @@ module OBSWS module Util - module String - def camelcase(s) - s.split("_").map(&:capitalize).join - end + module CoreExtensions + refine String do + def camelcase + split("_").map(&:capitalize).join + end - def snakecase(s) - s - .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') - .gsub(/([a-z\d])([A-Z])/, '\1_\2') - .downcase + def snakecase + gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .downcase + end end end end diff --git a/lib/obsws/version.rb b/lib/obsws/version.rb index 955ac65..683e7d4 100644 --- a/lib/obsws/version.rb +++ b/lib/obsws/version.rb @@ -11,7 +11,7 @@ module OBSWS end def patch - 1 + 2 end def to_a