Class: ConvenientService::Utils::String::Camelize Private
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::String::Camelize
- Defined in:
- lib/convenient_service/utils/string/camelize.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Converts strings to UpperCamelCase (capitalize_first_letter option is set to true by default).
Implementation is very basic just to serve the need of this library.
More comprehensive solution can be found in Rails, for example:
Instance Attribute Summary collapse
- #capitalize_first_letter ⇒ Object readonly private
- #string ⇒ Object readonly private
Instance Method Summary collapse
- #call ⇒ String private
- #initialize(string, capitalize_first_letter: true) ⇒ void constructor private
Methods inherited from Support::Command
Constructor Details
#initialize(string, capitalize_first_letter: true) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 |
# File 'lib/convenient_service/utils/string/camelize.rb', line 35 def initialize(string, capitalize_first_letter: true) @string = string.to_s @capitalize_first_letter = capitalize_first_letter end |
Instance Attribute Details
#capitalize_first_letter ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 |
# File 'lib/convenient_service/utils/string/camelize.rb', line 29 def capitalize_first_letter @capitalize_first_letter end |
#string ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 |
# File 'lib/convenient_service/utils/string/camelize.rb', line 23 def string @string end |
Instance Method Details
#call ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 46 47 48 49 |
# File 'lib/convenient_service/utils/string/camelize.rb', line 43 def call camelized = string.split(/[:_?!\-\ ]/).map { |part| upcase_first_char(part) }.join camelized[0] = camelized[0].downcase unless capitalize_first_letter camelized end |