Class: ConvenientService::Utils::String::Camelize
- Inherits:
-
Support::Command
- Object
- Support::Command
- ConvenientService::Utils::String::Camelize
- Defined in:
- lib/convenient_service/utils/string/camelize.rb
Overview
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
Returns the value of attribute capitalize_first_letter.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
Methods inherited from Support::Command
Constructor Details
#initialize(string, capitalize_first_letter: true) ⇒ void
30 31 32 33 |
# File 'lib/convenient_service/utils/string/camelize.rb', line 30 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)
Returns the value of attribute capitalize_first_letter.
24 25 26 |
# File 'lib/convenient_service/utils/string/camelize.rb', line 24 def capitalize_first_letter @capitalize_first_letter end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
18 19 20 |
# File 'lib/convenient_service/utils/string/camelize.rb', line 18 def string @string end |
Instance Method Details
#call ⇒ String
38 39 40 41 42 43 44 |
# File 'lib/convenient_service/utils/string/camelize.rb', line 38 def call camelized = string.split(/[:_?!\-\ ]/).map { |part| upcase_first_char(part) }.join camelized[0] = camelized[0].downcase unless capitalize_first_letter camelized end |