Class: Lotus::ApplicationName
- Inherits:
-
Object
- Object
- Lotus::ApplicationName
- Defined in:
- lib/lotus/application_name.rb
Overview
An application name.
Constant Summary collapse
- RESERVED_WORDS =
A list of words that are prohibited from forming the application name
%w(lotus).freeze
Class Method Summary collapse
-
.invalid?(name) ⇒ TrueClass, FalseClass
Returns true if a potential application name matches one of the reserved words.
Instance Method Summary collapse
-
#initialize(name) ⇒ Lotus::ApplicationName
constructor
Initialize and check against reserved words.
-
#to_env_s ⇒ String
Returns the application name uppercased with non-alphanumeric characters as underscores.
-
#to_s ⇒ String
Returns the cleaned application name.
Constructor Details
#initialize(name) ⇒ Lotus::ApplicationName
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 to be output roughly as given, but with the following changes:
-
downcased,
-
with surrounding spaces removed,
-
with internal whitespace rendered as underscores
-
with underscores de-duplicated
which is the default output. It must also be transformable into an environment variable.
30 31 32 33 |
# File 'lib/lotus/application_name.rb', line 30 def initialize(name) @name = sanitize(name) ensure_validity! end |
Class Method Details
.invalid?(name) ⇒ TrueClass, FalseClass
Returns true if a potential application name matches one of the reserved words.
70 71 72 |
# File 'lib/lotus/application_name.rb', line 70 def self.invalid?(name) RESERVED_WORDS.include?(name) end |
Instance Method Details
#to_env_s ⇒ String
Returns the application name uppercased with non-alphanumeric characters as underscores.
56 57 58 |
# File 'lib/lotus/application_name.rb', line 56 def to_env_s @name.upcase.gsub(/\W/, '_') end |
#to_s ⇒ String
Returns the cleaned application name.
43 44 45 |
# File 'lib/lotus/application_name.rb', line 43 def to_s @name end |