Module: Drum::Casings

Included in:
String
Defined in:
lib/drum/utils/ext.rb

Instance Method Summary collapse

Instance Method Details

#arraycaseArray<String>

Converts a string to ['array', 'case']

Returns:

  • (Array<String>)

    The arraycased version of the string



33
34
35
36
# File 'lib/drum/utils/ext.rb', line 33

def arraycase
  self.kebabcase
      .split('-')
end

#camelcaseString

Converts a string to camelCase.

Returns:

  • (String)

    The camelcased version of the string



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

#kebabcaseString

Converts a string to kebab-case.

Returns:

  • (String)

    The kebabcased version of the string



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

#pascalcaseString

Converts a string to PascalCase.

Returns:

  • (String)

    The pascalcased version of the string



60
61
62
63
64
# File 'lib/drum/utils/ext.rb', line 60

def pascalcase
  self.arraycase
      .map { |s| s.capitalize }
      .join
end

#startcaseString

Converts a string to Start Case.

Returns:

  • (String)

    The startcased version of the string



41
42
43
44
45
# File 'lib/drum/utils/ext.rb', line 41

def startcase
  self.arraycase
      .map { |s| s.capitalize }
      .join(' ')
end