module Drum::Casings

Public Instance Methods

arraycase() click to toggle source

Converts a string to [‘array’, ‘case’]

@return [Array<String>] The arraycased version of the string

# File lib/drum/utils/ext.rb, line 33
def arraycase
  self.kebabcase
      .split('-')
end
camelcase() click to toggle source

Converts a string to camelCase.

@return [String] The camelcased version of the string

# 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() click to toggle source

Converts a string to kebab-case.

@return [String] The kebabcased version of the string

# 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() click to toggle source

Converts a string to PascalCase.

@return [String] The pascalcased version of the string

# File lib/drum/utils/ext.rb, line 60
def pascalcase
  self.arraycase
      .map { |s| s.capitalize }
      .join
end
startcase() click to toggle source

Converts a string to Start Case.

@return [String] The startcased version of the string

# File lib/drum/utils/ext.rb, line 41
def startcase
  self.arraycase
      .map { |s| s.capitalize }
      .join(' ')
end