Module: Camel

Defined in:
lib/helpers/camel.rb

Overview

copy of Rails camelize and underscore (almost)

Class Method Summary collapse

Class Method Details

.ize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/helpers/camel.rb', line 4

def self.ize(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(/(^|_)(.)/) { $2.upcase }
  else
    lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
  end
end

.score(camel_cased_word) ⇒ Object



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

def self.score(camel_cased_word)
   word = camel_cased_word.to_s.dup
   word.gsub!(/::/, '_')  #except I changed '/' to '_'
   word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
   word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
   word.tr!("-", "_")
   word.downcase!
   word
end