Class: CouchPopulator::MiscHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/couchpopulator/misc_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/couchpopulator/misc_helper.rb', line 11

def 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

.camelize_and_constantize(lower_case_and_underscored_word) ⇒ Object



5
6
7
# File 'lib/couchpopulator/misc_helper.rb', line 5

def camelize_and_constantize(lower_case_and_underscored_word)
   constantize(camelize(lower_case_and_underscored_word))
end

Instance Method Details

#constantize(camel_cased_word) ⇒ Object

:nodoc:



39
40
41
42
43
44
45
46
47
48
# File 'lib/couchpopulator/misc_helper.rb', line 39

def constantize(camel_cased_word)
  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
  constant
end