lib/hanami/application_name.rb in hanami-0.7.3 vs lib/hanami/application_name.rb in hanami-0.8.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'hanami/utils/string'
+
module Hanami
# An application name.
#
# @since 0.2.1
class ApplicationName
@@ -32,20 +34,24 @@
ensure_validity!
end
# Returns the cleaned application name.
#
- # @return [String] the santized name
+ # @return [String] the sanitized name
#
# @example
- # ApplicationName.new("my-App ").to_s # => "my-app"
+ # ApplicationName.new("my-App ").to_s # => "my_app"
#
# @since 0.2.1
def to_s
@name
end
+ # @api private
+ # @since 0.8.0
+ alias_method :to_str, :to_s
+
# Returns the application name uppercased with non-alphanumeric characters
# as underscores.
#
# @return [String] the upcased name
#
@@ -88,14 +94,11 @@
# Cleans a string to be a functioning application name.
#
# @api private
# @since 0.2.1
def sanitize(name)
- name
- .downcase
- .strip
- .gsub(/\s/, '_')
- .gsub(/_{2,}/, '_')
- .gsub(/-/, '_')
+ Utils::String.new(
+ name.strip
+ ).underscore.to_s
end
end
end