From 9a702b528c540be93d504d3823116834c6dd49a6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 16 Dec 2015 22:47:10 +0100 Subject: [PATCH] Code cleanup, improved String.to_filename. --- lib/application_lib.rb | 6 +++--- lib/core_ext/string.rb | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/application_lib.rb b/lib/application_lib.rb index a9fa4255f..a5e94864f 100644 --- a/lib/application_lib.rb +++ b/lib/application_lib.rb @@ -9,7 +9,7 @@ module ApplicationLib load adapter based on setting option - result = self.load_adapter_by_setting( 'some_setting_with_class_name' ) + result = self.load_adapter_by_setting('some_setting_with_class_name') returns @@ -18,7 +18,7 @@ returns =end def load_adapter_by_setting(setting) - adapter = Setting.get( setting ) + adapter = Setting.get(setting) return if !adapter # load backend @@ -29,7 +29,7 @@ returns load adapter - result = self.load_adapter( 'Some::Classname' ) + result = self.load_adapter('Some::Classname') returns diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index 049e88e6c..b060d80bb 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -32,7 +32,10 @@ class String def to_filename camel_cased_word = "#{self}" - camel_cased_word.gsub(/::/, '/').downcase + camel_cased_word.gsub(/::/, '/') + .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .tr('-', '_').downcase end =begin