Class: ZohoHub::StringUtils
- Inherits:
-
Object
- Object
- ZohoHub::StringUtils
- Defined in:
- lib/zoho_hub/string_utils.rb
Class Method Summary collapse
- .camelize(text) ⇒ Object
- .demodulize(text) ⇒ Object
- .pluralize(text) ⇒ Object
- .underscore(text) ⇒ Object
Class Method Details
.camelize(text) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/zoho_hub/string_utils.rb', line 18 def camelize(text) result = text.split(/[_\s]/) return result.first if result.size == 1 result.map(&:capitalize).join end |
.demodulize(text) ⇒ Object
6 7 8 |
# File 'lib/zoho_hub/string_utils.rb', line 6 def demodulize(text) text.split('::').last end |
.pluralize(text) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/zoho_hub/string_utils.rb', line 10 def pluralize(text) if defined?(ActiveSupport::Inflector) ActiveSupport::Inflector.pluralize(text) else "#{text}s" end end |
.underscore(text) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/zoho_hub/string_utils.rb', line 26 def underscore(text) return text unless text =~ /[A-Z-]/ result = text.dup result.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') result.gsub!(/([a-z\d])([A-Z])/, '\1_\2') result.tr!('-', '_') result.downcase! result end |