Replace period in underscored string (#398)

This commit is contained in:
Benjamin Klotz 2022-11-07 10:48:27 +01:00 committed by GitHub
parent 675ce1ca8d
commit a340ac153c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -231,7 +231,7 @@ module Hanami
string.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
string.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
string.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
string.gsub!(/[[:space:]]|-/, UNDERSCORE_DIVISION_TARGET)
string.gsub!(/[[:space:]]|-|\./, UNDERSCORE_DIVISION_TARGET)
string.downcase
end

View File

@ -198,6 +198,11 @@ RSpec.describe Hanami::Utils::String do
expect(string).to eq("hanami_utils")
end
it "handles periods" do
string = Hanami::Utils::String.underscore("hanami.utils")
expect(string).to eq("hanami_utils")
end
it "handles spaces" do
string = Hanami::Utils::String.underscore("Hanami Utils")
expect(string).to eq("hanami_utils")