Sha256: 1c59d3e191a7c88098c78bccbf0dcce345a551db67b917f51762eaefed18b3c9

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# TITLE:
#
#  String Case Extensions
#
# SUMMARY:
#
#   String case-related extensions.
#
# CREDIT:
#
#   - Phil Tomson
#   - Thomas Sawyer
#
# TODO:
#
#   - Perhaps add camelcase methods.

#
class String

  # Title case.

  def titlecase
    gsub(/\b\w/){$&.upcase}
  end

  # Return true if the string is capitalized, otherwise false.
  #
  #   "THIS".capitalized?  #=> true
  #   "This".capitalized?  #=> true
  #   "this".capitalized?  #=> false
  #
  # CREDIT: Phil Tomson

  def capitalized?
    self =~ /^[A-Z]/
  end


  # Return true if the string is lowercase (downcase), otherwise false.
  #
  #   "THIS".downcase?  #=> false
  #   "This".downcase?  #=> false
  #   "this".downcase?  #=> true
  #
  # CREDIT Phil Tomson

  def downcase?
    downcase == self
  end


  # Is the string upcase/uppercase?
  #
  #   "THIS".upcase?  #=> true
  #   "This".upcase?  #=> false
  #   "this".upcase?  #=> false
  #
  # CREDIT Phil Tomson

  def upcase?
    self.upcase == self
  end

  # Alias for #downcase? method.
  alias_method :lowercase?, :downcase?

  # Alias for #upcase? method.
  alias_method :uppercase?, :upcase?
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-2.1.1 lib/core/facets/string/case.rb
facets-2.1.2 lib/core/facets/string/case.rb
facets-2.1.3 lib/core/facets/string/case.rb