Module: Chingu::Inflector

Defined in:
lib/chingu/inflector.rb

Class Method Summary collapse

Class Method Details

.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object

“automatic_assets” -> “AutomaticAssets”



29
30
31
32
33
34
35
# File 'lib/chingu/inflector.rb', line 29

def Inflector.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  else
    lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
  end
end

.demodulize(class_name_in_module) ⇒ Object

“Chingu::GameObject” -> “GameObject”



40
41
42
# File 'lib/chingu/inflector.rb', line 40

def Inflector.demodulize(class_name_in_module)
  class_name_in_module.to_s.gsub(/^.*::/, '')
end

.underscore(camel_cased_word) ⇒ Object

“FireBall” -> “fire_ball”



47
48
49
50
51
52
# File 'lib/chingu/inflector.rb', line 47

def Inflector.underscore(camel_cased_word)
	camel_cased_word.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
	gsub(/([a-z\d])([A-Z])/,'\1_\2').
	tr("-", "_").
	downcase
end