Class: String

Inherits:
Object show all
Defined in:
lib/csv_record/helpers.rb

Instance Method Summary collapse

Instance Method Details

#constantizeObject



22
23
24
# File 'lib/csv_record/helpers.rb', line 22

def constantize
  self.split('_').map { |w| w.capitalize }.join
end

#to_classObject



25
26
27
# File 'lib/csv_record/helpers.rb', line 25

def to_class
  Object.const_get self.constantize.singularize
end

#underscoreObject



28
29
30
31
32
33
34
# File 'lib/csv_record/helpers.rb', line 28

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