Sha256: d85927855a491b06846c7f2e909e0c3dc14a12882c034c9d33e85a8ff1b8d441
Contents?: true
Size: 795 Bytes
Versions: 12
Compression:
Stored size: 795 Bytes
Contents
require 'forwardable' # Avoid the monkey patching of String for underscore/titleize/humanize class StringExtra extend Forwardable def_delegators(:@string, *String.public_instance_methods(false)) def initialize(str = 'no_name') @string = (str.length > 60) ? 'long_name' : str end def titleize gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase .gsub(/_id$/, '') .gsub(/_/, ' ').capitalize .gsub(/\b([a-z])/) { $1.capitalize } end def humanize gsub(/_id$/, '').gsub(/_/, ' ').capitalize end def underscore gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end end
Version data entries
12 entries across 12 versions & 2 rubygems