Class: Cistern::String
- Inherits:
-
Object
- Object
- Cistern::String
- Defined in:
- lib/cistern/string.rb
Class Method Summary collapse
- .camelize(string) ⇒ Object
-
.demodulize(path) ⇒ Object
File activesupport/lib/active_support/inflector/methods.rb, line 168.
- .pluralize(string) ⇒ Object
-
.underscore(camel_cased_word) ⇒ Object
File activesupport/lib/active_support/inflector/methods.rb, line 90.
Class Method Details
.camelize(string) ⇒ Object
2 3 4 |
# File 'lib/cistern/string.rb', line 2 def self.camelize(string) string.gsub(/[A-Z]+/) { |w| "_#{w.downcase}" }.gsub(/^_/, '') end |
.demodulize(path) ⇒ Object
File activesupport/lib/active_support/inflector/methods.rb, line 168
18 19 20 21 22 23 24 25 |
# File 'lib/cistern/string.rb', line 18 def self.demodulize(path) path = path.to_s if i = path.rindex('::') path[(i + 2)..-1] else path end end |
.pluralize(string) ⇒ Object
28 29 30 |
# File 'lib/cistern/string.rb', line 28 def self.pluralize(string) "#{string}s" end |
.underscore(camel_cased_word) ⇒ Object
File activesupport/lib/active_support/inflector/methods.rb, line 90
7 8 9 10 11 12 13 14 15 |
# File 'lib/cistern/string.rb', line 7 def self.underscore(camel_cased_word) word = camel_cased_word.to_s.gsub('::', '/') # word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr!('-', '_') word.downcase! word end |