brew style
This commit is contained in:
parent
544960b4fc
commit
6ffda80a8a
@ -62,7 +62,8 @@ describe Utils do
|
|||||||
describe ".underscore" do
|
describe ".underscore" do
|
||||||
# commented out entries require acronyms inflections
|
# commented out entries require acronyms inflections
|
||||||
let(:words) {
|
let(:words) {
|
||||||
[["API", "api"],
|
[
|
||||||
|
["API", "api"],
|
||||||
["APIController", "api_controller"],
|
["APIController", "api_controller"],
|
||||||
["Nokogiri::HTML", "nokogiri/html"],
|
["Nokogiri::HTML", "nokogiri/html"],
|
||||||
# ["HTTPAPI", "http_api"],
|
# ["HTTPAPI", "http_api"],
|
||||||
@ -83,7 +84,8 @@ describe Utils do
|
|||||||
["HttpsApis", "https_apis"],
|
["HttpsApis", "https_apis"],
|
||||||
["Html5", "html5"],
|
["Html5", "html5"],
|
||||||
["Restfully", "restfully"],
|
["Restfully", "restfully"],
|
||||||
["RoRails", "ro_rails"]]
|
["RoRails", "ro_rails"],
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
it "converts strings to underscore case" do
|
it "converts strings to underscore case" do
|
||||||
|
@ -144,8 +144,11 @@ module Utils
|
|||||||
sig { params(camel_cased_word: T.any(String, Symbol)).returns(String) }
|
sig { params(camel_cased_word: T.any(String, Symbol)).returns(String) }
|
||||||
def self.underscore(camel_cased_word)
|
def self.underscore(camel_cased_word)
|
||||||
return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
|
return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
|
||||||
|
|
||||||
word = camel_cased_word.to_s.gsub("::", "/")
|
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.tr!("-", "_")
|
||||||
word.downcase!
|
word.downcase!
|
||||||
word
|
word
|
||||||
|
Loading…
x
Reference in New Issue
Block a user