brew style

This commit is contained in:
Douglas Eichelberger 2023-03-07 10:14:57 -08:00
parent 544960b4fc
commit 6ffda80a8a
2 changed files with 29 additions and 24 deletions

View File

@ -61,29 +61,31 @@ describe Utils do
describe ".underscore" do
# commented out entries require acronyms inflections
let (:words) {
[["API", "api"],
["APIController", "api_controller"],
["Nokogiri::HTML", "nokogiri/html"],
# ["HTTPAPI", "http_api"],
["HTTP::Get", "http/get"],
["SSLError", "ssl_error"],
# ["RESTful", "restful"],
# ["RESTfulController", "restful_controller"],
# ["Nested::RESTful", "nested/restful"],
# ["IHeartW3C", "i_heart_w3c"],
# ["PhDRequired", "phd_required"],
# ["IRoRU", "i_ror_u"],
# ["RESTfulHTTPAPI", "restful_http_api"],
# ["HTTP::RESTful", "http/restful"],
# ["HTTP::RESTfulAPI", "http/restful_api"],
# ["APIRESTful", "api_restful"],
["Capistrano", "capistrano"],
["CapiController", "capi_controller"],
["HttpsApis", "https_apis"],
["Html5", "html5"],
["Restfully", "restfully"],
["RoRails", "ro_rails"]]
let(:words) {
[
["API", "api"],
["APIController", "api_controller"],
["Nokogiri::HTML", "nokogiri/html"],
# ["HTTPAPI", "http_api"],
["HTTP::Get", "http/get"],
["SSLError", "ssl_error"],
# ["RESTful", "restful"],
# ["RESTfulController", "restful_controller"],
# ["Nested::RESTful", "nested/restful"],
# ["IHeartW3C", "i_heart_w3c"],
# ["PhDRequired", "phd_required"],
# ["IRoRU", "i_ror_u"],
# ["RESTfulHTTPAPI", "restful_http_api"],
# ["HTTP::RESTful", "http/restful"],
# ["HTTP::RESTfulAPI", "http/restful_api"],
# ["APIRESTful", "api_restful"],
["Capistrano", "capistrano"],
["CapiController", "capi_controller"],
["HttpsApis", "https_apis"],
["Html5", "html5"],
["Restfully", "restfully"],
["RoRails", "ro_rails"],
]
}
it "converts strings to underscore case" do

View File

@ -144,8 +144,11 @@ module Utils
sig { params(camel_cased_word: T.any(String, Symbol)).returns(String) }
def self.underscore(camel_cased_word)
return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
word = camel_cased_word.to_s.gsub("::", "/")
word.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { ($1 || $2) << "_" }
word.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
(::Regexp.last_match(1) || ::Regexp.last_match(2)) << "_"
end
word.tr!("-", "_")
word.downcase!
word