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

Version Path
ruby-processing-2.6.12 lib/ruby-processing/helpers/string_extra.rb
ruby-processing-2.6.11 lib/ruby-processing/helpers/string_extra.rb
jruby_art-0.2.6.pre lib/jruby_art/helpers/string_extra.rb
ruby-processing-2.6.10 lib/ruby-processing/helpers/string_extra.rb
ruby-processing-2.6.9 lib/ruby-processing/helpers/string_extra.rb
ruby-processing-2.6.8 lib/ruby-processing/helpers/string_extra.rb
jruby_art-0.2.4.pre lib/jruby_art/helpers/string_extra.rb
jruby_art-0.2.3.pre lib/jruby_art/helpers/string_extra.rb
jruby_art-0.2.2.pre lib/jruby_art/helpers/string_extra.rb
jruby_art-0.2.1.pre lib/jruby_art/helpers/string_extra.rb
ruby-processing-2.6.7 lib/ruby-processing/helpers/string_extra.rb
jruby_art-0.2.0.pre lib/jruby_art/helpers/string_extra.rb