lib/lotus/application_name.rb in lotusrb-0.5.0 vs lib/lotus/application_name.rb in lotusrb-0.6.0

- old
+ new

@@ -7,11 +7,10 @@ # A list of words that are prohibited from forming the application name # # @since 0.2.1 RESERVED_WORDS = %w(lotus).freeze - # Initialize and check against reserved words # # An application name needs to be translated in quite a few ways: # First, it must be checked against a list of reserved words and rejected # if it is invalid. Secondly, assuming it is not invalid, it must be able @@ -31,46 +30,49 @@ def initialize(name) @name = sanitize(name) ensure_validity! end - # Returns the cleaned application name. # + # @return [String] the santized name + # # @example # ApplicationName.new("my-App ").to_s # => "my-app" # # @since 0.2.1 def to_s @name end - # Returns the application name uppercased with non-alphanumeric characters # as underscores. # + # @return [String] the upcased name + # # @example # ApplicationName.new("my-app").to_env_s => "MY_APP" # # @since 0.2.1 def to_env_s @name.upcase.gsub(/\W/, '_') end - # Returns true if a potential application name matches one of the reserved # words. # + # @param name [String] the application name + # @return [TrueClass, FalseClass] the result of the check + # # @example # Lotus::ApplicationName.invalid?("lotus") # => true # # @since 0.2.1 def self.invalid?(name) RESERVED_WORDS.include?(name) end - private # Raises RuntimeError with explanation if the provided name is invalid. # # @api private @@ -81,19 +83,19 @@ "application name must not be any one of the following: " + RESERVED_WORDS.join(", ") end end - # 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(/-/, '_') end end end