Module: AppPermissionStatistics::Inflector

Included in:
String
Defined in:
lib/app_permission_statistics/core_ext/inflector.rb

Instance Method Summary collapse

Instance Method Details

#ai_camelcase(first_letter: :upper, separators: ['-', '_', '\s']) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/app_permission_statistics/core_ext/inflector.rb', line 14

def ai_camelcase(first_letter: :upper, separators: ['-', '_', '\s'])
  str = dup

  separators.each do |s|
    str = str.gsub(/(?:#{s}+)([a-z])/) { $1.upcase }
  end

  case first_letter
  when :upper, true
    str = str.gsub(/(\A|\s)([a-z])/) { $1 + $2.upcase }
  when :lower, false
    str = str.gsub(/(\A|\s)([A-Z])/) { $1 + $2.downcase }
  end

  str
end

#ai_snakecaseObject



5
6
7
8
9
10
11
12
# File 'lib/app_permission_statistics/core_ext/inflector.rb', line 5

def ai_snakecase
  gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr('-', '_')
    .gsub(/\s/, '_')
    .gsub(/__+/, '_')
    .downcase
end