<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Patrick Tulskie &#187; names</title>
	<atom:link href="http://www.patricktulskie.com/tag/names/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.patricktulskie.com</link>
	<description>Building a Better Internet</description>
	<lastBuildDate>Wed, 16 Jun 2010 19:12:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ruby String#Nameize Revised</title>
		<link>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/</link>
		<comments>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 19:10:31 +0000</pubDate>
		<dc:creator>Patrick Tulskie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[irish]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mc]]></category>
		<category><![CDATA[nameize]]></category>
		<category><![CDATA[names]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.patricktulskie.com/?p=102</guid>
		<description><![CDATA[Ruby String class extension to capitalize names properly, including Irish names with Mc, Mac, and O' in them.]]></description>
			<content:encoded><![CDATA[<p>This morning, Kevin Glowacz (<a href="http://twitter.com/kevinglowacz">@kevinglowacz</a>) replied to me a few times on Twitter about Ruby String#Nameize class extension I had posted a while back.  I had done some work to it after posting it here.  Kevin also asked me a few questions about oddities that were in it that have since been resolved.  So thanks to his prodding, you get a slightly updated version&#8230;</p>
<p>The only real &#8220;feature&#8221; is that it will now handle full names just fine. Otherwise, the rest of the stuff was mostly performance related.  Here it is:</p>
<pre><code>class String
  # Extension of the string class to properly handle camel names
  def nameize
    if self.match(/ /)
      # If the name has a space in it, we gotta run the parts through the nameizer.
      name = self.split(' ').each { |part| part.nameize! }.join(' ')
      return name
    elsif self.match(/^[A-Z]/)
      # If they took the time to capitalize their name then let's just jump out.
      return self
    else
      # If there are no spaces and there is no prior
      # capitalization then let's downcase the whole thing.
      name = self.downcase
    end
    # Let's now assume that they were lazy...
    return case
    when name.match(/^mac/)
      name.gsub(/^mac/, "").capitalize.insert(0, "Mac")
    when name.match(/^mc/)
      name.gsub(/^mc/, "").capitalize.insert(0, "Mc")
    when name.match(/^o\'/)
      name.split("'").each{ |piece| piece.capitalize! }.join("'")
    else
      name.capitalize # name is a first name or it's not Irish then capitalize it.
    end
  end

  def nameize!
    replace nameize # BANG!
  end

end</code></pre>
<p>As always &#8211; question, comments, suggestions &#8211; shoot me an email, leave a comment, or hit me on Twitter (@PatrickTulskie).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patricktulskie.com/2008/12/ruby-string-nameize-revised/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

