Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
BSD-LICENSE.txt | Thu May 22 04:12:14 -0700 2008 | |
| |
GPL-LICENSE.txt | Thu May 22 04:12:14 -0700 2008 | |
| |
README.markdown | Wed Aug 13 10:41:28 -0700 2008 | |
| |
title_case.rb | Wed Aug 13 10:38:08 -0700 2008 | |
| |
title_case_test.rb | Wed Aug 13 10:38:08 -0700 2008 |
Ruby Title Case
This is a Ruby implementation of John Gruber's Title Case by Paul Mucur.
Usage
Simply include the TitleCase module into your string class. For example, inside a Ruby script or an irb session:
require 'title_case'
class String
include TitleCase
end
"Hello there".title_case
Alternatively, it can be used from the command-line:
ruby title_case.rb "Hello there"
echo "An amazing headline" | ruby title_case.rb
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"







