Class: Mangadex::Utils

Inherits:
Object show all
Defined in:
lib/mangadex/utils.rb

Class Method Summary collapse

Class Method Details

.camelize(string, uppercase_first_letter = false) ⇒ Object



6
7
8
9
10
# File 'lib/mangadex/utils.rb', line 6

def camelize(string, uppercase_first_letter = false)
  string.split('_').each_with_index.map do |x, i|
    i == 0 && !uppercase_first_letter ? x : x.capitalize
  end.join
end

.underscore(string) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/mangadex/utils.rb', line 12

def underscore(string)
  is_symbol = string.kind_of?(Symbol)
  data = string.to_s
  result = data.gsub(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
    ($1 || $2) << "_"
  end.tr('-', '_').downcase

  is_symbol ? result.to_sym : result
end