Sha256: 05b1d57af775dbd04c5406480e7f96f8f563542a47cc1dc920306cec17490873

Contents?: true

Size: 780 Bytes

Versions: 13

Compression:

Stored size: 780 Bytes

Contents

class String #:nodoc:
  
  def titleize
    self.underscore.humanize.gsub(/\b([a-z])/) { $1.capitalize }
  end
  
  def humanize()
    self.gsub(/_id$/, "").gsub(/_/, " ").capitalize
  end
  
  def camelize(first_letter_in_uppercase = true)
    if first_letter_in_uppercase
      self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
    else
      self.first + self.camelize[1..-1]
    end
  end
  
  def underscore
    self.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
  end
  
  # String.ord is Ruby 1.9, so this is a little fix for R 1.8 
  # to make it forward compatible and readable
  unless String.method_defined? :ord
  	def ord
  		self[0]
  	end
  end  
  
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ruby-processing-2.4.4 lib/ruby-processing/helpers/string.rb
ruby-processing-2.4.3 lib/ruby-processing/helpers/string.rb
ruby-processing-2.4.2 lib/ruby-processing/helpers/string.rb
ruby-processing-2.4.1 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.11 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.10.1 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.9 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.3 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.4 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.5 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.6 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.7 lib/ruby-processing/helpers/string.rb
ruby-processing-1.0.8 lib/ruby-processing/helpers/string.rb