Module: Drum::Casings
- Included in:
- String
- Defined in:
- lib/drum/utils/ext.rb
Instance Method Summary collapse
-
#arraycase ⇒ Array<String>
Converts a string to ['array', 'case'].
-
#camelcase ⇒ String
Converts a string to camelCase.
-
#kebabcase ⇒ String
Converts a string to kebab-case.
-
#pascalcase ⇒ String
Converts a string to PascalCase.
-
#startcase ⇒ String
Converts a string to Start Case.
Instance Method Details
#arraycase ⇒ Array<String>
Converts a string to ['array', 'case']
33 34 35 36 |
# File 'lib/drum/utils/ext.rb', line 33 def arraycase self.kebabcase .split('-') end |
#camelcase ⇒ String
Converts a string to camelCase.
50 51 52 53 54 55 |
# File 'lib/drum/utils/ext.rb', line 50 def camelcase self.arraycase .each_with_index .map { |s, i| if i == 0 then s else s.capitalize end } .join end |
#kebabcase ⇒ String
Converts a string to kebab-case.
23 24 25 26 27 28 |
# File 'lib/drum/utils/ext.rb', line 23 def kebabcase self.gsub(/([A-Z]+)([A-Z][a-z])/,'\1-\2') .gsub(/([a-z\d])([A-Z])/,'\1-\2') .gsub(/[\s_\/\-_:\.]+/, '-') .downcase end |
#pascalcase ⇒ String
Converts a string to PascalCase.
60 61 62 63 64 |
# File 'lib/drum/utils/ext.rb', line 60 def pascalcase self.arraycase .map { |s| s.capitalize } .join end |
#startcase ⇒ String
Converts a string to Start Case.
41 42 43 44 45 |
# File 'lib/drum/utils/ext.rb', line 41 def startcase self.arraycase .map { |s| s.capitalize } .join(' ') end |