Sha256: b72143ade49128119219ac0ffec39069abb6c1fe34a00587716d5c790b1b9da1

Contents?: true

Size: 551 Bytes

Versions: 7

Compression:

Stored size: 551 Bytes

Contents

class String #:nodoc:
  def titleize
    underscore.humanize.gsub(/\b([a-z])/) { $1.capitalize }
  end

  def humanize
    gsub(/_id$/, '').gsub(/_/, ' ').capitalize
  end

  def camelize(first_letter_in_uppercase = true)
    if first_letter_in_uppercase
      gsub(/\/(.?)/) { '::' + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
    else
      first + camelize[1..-1]
    end
  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

7 entries across 7 versions & 1 rubygems

Version Path
ruby-processing-2.6.6 lib/ruby-processing/helpers/string.rb
ruby-processing-2.6.5 lib/ruby-processing/helpers/string.rb
ruby-processing-2.6.4 lib/ruby-processing/helpers/string.rb
ruby-processing-2.6.3 lib/ruby-processing/helpers/string.rb
ruby-processing-2.6.2 lib/ruby-processing/helpers/string.rb
ruby-processing-2.6.1 lib/ruby-processing/helpers/string.rb
ruby-processing-2.6.0 lib/ruby-processing/helpers/string.rb