Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Ruby implementation of John Gruber's Title Case.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 BSD-LICENSE.txt
Octocat-spinner-32 GPL-LICENSE.txt
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
README.markdown

Ruby Title Case Build Status

This is a Ruby implementation of John Gruber's Title Case by Paul Mucur.

Usage

Simply pass any string to which you wish to apply title casing to the Title initializer and then use the to_title_case method. A Title instance has all the methods of the original string and so should be suitable for using interchangably with it.

For example:

require 'title'

greeting = Title.new("Hello there")
greeting.to_title_case
# => "Hello There"

Didn't this library previously re-open the String class and use DCI?

Yes, but I have since learnt the error of my ways.

Known Issues

Unlike the original Perl implementation, this version does not correctly capitalise characters such as é and is therefore limited in scope to strings consisting only of ASCII printable characters. A workaround would be to stop relying on the Ruby regular expression patterns of [A-Z], \w and \W for detecting capital letters, alphanumeric characters and non-alphanumeric characters respectively.

While it will deal with most common usage where you need a reasonably-correctly-cased sentence to be made suitable for a title, it will not correct mistakes such as lowercase acronyms or errant capital letters:

"at&t"  => "At&t"
"HellO" => "HellO"
Something went wrong with that request. Please try again.