Class: StringExtra
- Inherits:
-
Object
- Object
- StringExtra
- Extended by:
- Forwardable
- Defined in:
- lib/jruby_art/helpers/string_extra.rb
Overview
reverting to StringExtra class, from a module with String refinements
Instance Method Summary collapse
- #camelize ⇒ Object
- #humanize ⇒ Object
-
#initialize(str) ⇒ StringExtra
constructor
A new instance of StringExtra.
- #titleize ⇒ Object
- #underscore ⇒ Object
Constructor Details
#initialize(str) ⇒ StringExtra
Returns a new instance of StringExtra.
7 8 9 |
# File 'lib/jruby_art/helpers/string_extra.rb', line 7 def initialize(str) @str = str end |
Instance Method Details
#camelize ⇒ Object
21 22 23 24 |
# File 'lib/jruby_art/helpers/string_extra.rb', line 21 def camelize gsub(%r{/\/(.?)/}) { '::' + Regexp.last_match[1].upcase } .gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase } end |
#humanize ⇒ Object
17 18 19 |
# File 'lib/jruby_art/helpers/string_extra.rb', line 17 def humanize gsub(/_id$/, '').tr('_', ' ').capitalize end |
#titleize ⇒ Object
11 12 13 14 15 |
# File 'lib/jruby_art/helpers/string_extra.rb', line 11 def titleize underscore .gsub(/_id$/, '').tr('_', ' ').capitalize .gsub(/\b([a-z])/) { Regexp.last_match[1].capitalize } end |
#underscore ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/jruby_art/helpers/string_extra.rb', line 26 def underscore gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |