Module: Kernel
- Defined in:
- lib/hot_potato/utils.rb
Instance Method Summary collapse
-
#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object
Taken from Rails ActiveSupport::Inflector.
-
#classify(name) ⇒ Object
Taken from Rails ActiveSupport::Inflector.
-
#underscore(camel_cased_word) ⇒ Object
Taken from Rails ActiveSupport::Inflector.
Instance Method Details
#camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object
Taken from Rails ActiveSupport::Inflector
24 25 26 27 28 29 30 |
# File 'lib/hot_potato/utils.rb', line 24 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.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1] end end |
#classify(name) ⇒ Object
Taken from Rails ActiveSupport::Inflector
18 19 20 21 |
# File 'lib/hot_potato/utils.rb', line 18 def classify(name) # strip out any leading schema name camelize(name.to_s.sub(/.*\./, '')) end |
#underscore(camel_cased_word) ⇒ Object
Taken from Rails ActiveSupport::Inflector
33 34 35 36 37 38 39 40 41 |
# File 'lib/hot_potato/utils.rb', line 33 def underscore(camel_cased_word) word = camel_cased_word.to_s.dup word.gsub!(/::/, '/') 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 |