Sha256: f3a3e20f6076bc290bfccc5bbdcd6ce1d4041279e72aec4c51fca9afed1ee356

Contents?: true

Size: 813 Bytes

Versions: 22

Compression:

Stored size: 813 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])/) { Regexp.last_match[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

22 entries across 22 versions & 2 rubygems

Version Path
ruby-processing-2.7.1 lib/ruby-processing/helpers/string_extra.rb
ruby-processing-2.7.0 lib/ruby-processing/helpers/string_extra.rb
ruby-processing-2.6.18 lib/ruby-processing/helpers/string_extra.rb
ruby-processing-2.6.17 lib/ruby-processing/helpers/string_extra.rb
jruby_art-1.0.4 lib/jruby_art/helpers/string_extra.rb
jruby_art-1.0.3 lib/jruby_art/helpers/string_extra.rb
jruby_art-1.0.2 lib/jruby_art/helpers/string_extra.rb
ruby-processing-2.6.16 lib/ruby-processing/helpers/string_extra.rb
jruby_art-1.0.1 lib/jruby_art/helpers/string_extra.rb
jruby_art-1.0.0 lib/jruby_art/helpers/string_extra.rb
jruby_art-0.9.0 lib/jruby_art/helpers/string_extra.rb
jruby_art-0.8.0 lib/jruby_art/helpers/string_extra.rb
jruby_art-0.7.0 lib/jruby_art/helpers/string_extra.rb
jruby_art-0.6.0 lib/jruby_art/helpers/string_extra.rb
jruby_art-0.5.0 lib/jruby_art/helpers/string_extra.rb
ruby-processing-2.6.15 lib/ruby-processing/helpers/string_extra.rb
jruby_art-0.4.2 lib/jruby_art/helpers/string_extra.rb
ruby-processing-2.6.14 lib/ruby-processing/helpers/string_extra.rb
jruby_art-0.4.0 lib/jruby_art/helpers/string_extra.rb
jruby_art-0.3.1.pre lib/jruby_art/helpers/string_extra.rb