<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
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/"
> <channel><title>Comments on: How A Ruby Case Statement Works And What You Can Do With It</title> <atom:link href="http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/feed/" rel="self" type="application/rss+xml" /><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/</link> <description>For the betterment of the software craft...</description> <lastBuildDate>Mon, 21 Nov 2011 13:57:06 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.2</generator> <item><title>By: Suresh Nambiar</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-7100</link> <dc:creator>Suresh Nambiar</dc:creator> <pubDate>Sun, 24 Apr 2011 14:42:04 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-7100</guid> <description>Slightly modified version...
Provides a function to convert a dateString to date.
def server_format_date ( strdate )
strdt = strdate.chomp.strip
case strdt.gsub(/\D/,&quot;-&quot;)
when /\d{8}/ then Date.strptime(strdt, &quot;%d%m%Y&quot;)
when /\d{7}/ then Date.strptime(&#039;0&#039; + strdt, &quot;%d%m%Y&quot;)
when /\d{6}/ then Date.strptime(strdt, &quot;%d%m%y&quot;)
when /\d{5}/ then Date.strptime(&#039;0&#039; + strdt, &quot;%d%m%y&quot;)
when /\d{4}/ then Date.strptime(strdt[0] + &quot;-&quot; + strdt[1] + &quot;-&quot; + strdt[2..3], &quot;%d-%m-%y&quot;)
when /\d{2}-\d{2}-\d{4}/ then Date.strptime(strdt, &quot;%d-%m-%Y&quot;)
when /\d{2}-\d{2}-\d{2}/ then Date.strptime(strdt, &quot;%d-%m-%y&quot;)
when /\d{4}-\d{2}-\d{2}/ then Date.strptime(strdt, &quot;%Y-%m-%d&quot;)
end
end
Test Cases :-
server_format_date ( &#039;2011-3-4&#039; )
server_format_date ( &#039;2011-3-04&#039; )
server_format_date ( &#039;2011-03-4&#039; )
server_format_date ( &#039;2011-03-04&#039; )
server_format_date ( &#039;4-3-2011&#039; )
server_format_date ( &#039;04-3-2011&#039; )
server_format_date ( &#039;4-03-2011&#039; )
server_format_date ( &#039;04-03-2011&#039; )
server_format_date ( &#039;4311&#039; )
server_format_date ( &#039;40311&#039; )
server_format_date ( &#039;040311&#039; )
server_format_date ( &#039;4032011&#039; )
server_format_date ( &#039;04032011&#039; )</description> <content:encoded><![CDATA[<p>Slightly modified version&#8230;<br
/> Provides a function to convert a dateString to date.</p><p> def server_format_date ( strdate )<br
/> strdt = strdate.chomp.strip<br
/> case strdt.gsub(/\D/,&#8221;-&#8221;)<br
/> when /\d{8}/ then Date.strptime(strdt, &#8220;%d%m%Y&#8221;)<br
/> when /\d{7}/ then Date.strptime(&#8217;0&#8242; + strdt, &#8220;%d%m%Y&#8221;)<br
/> when /\d{6}/ then Date.strptime(strdt, &#8220;%d%m%y&#8221;)<br
/> when /\d{5}/ then Date.strptime(&#8217;0&#8242; + strdt, &#8220;%d%m%y&#8221;)<br
/> when /\d{4}/ then Date.strptime(strdt[0] + &#8220;-&#8221; + strdt[1] + &#8220;-&#8221; + strdt[2..3], &#8220;%d-%m-%y&#8221;)<br
/> when /\d{2}-\d{2}-\d{4}/ then Date.strptime(strdt, &#8220;%d-%m-%Y&#8221;)<br
/> when /\d{2}-\d{2}-\d{2}/ then Date.strptime(strdt, &#8220;%d-%m-%y&#8221;)<br
/> when /\d{4}-\d{2}-\d{2}/ then Date.strptime(strdt, &#8220;%Y-%m-%d&#8221;)<br
/> end<br
/> end</p><p>Test Cases :-</p><p> server_format_date ( &#8217;2011-3-4&#8242; )<br
/> server_format_date ( &#8217;2011-3-04&#8242; )<br
/> server_format_date ( &#8217;2011-03-4&#8242; )<br
/> server_format_date ( &#8217;2011-03-04&#8242; )</p><p> server_format_date ( &#8217;4-3-2011&#8242; )<br
/> server_format_date ( &#8217;04-3-2011&#8242; )<br
/> server_format_date ( &#8217;4-03-2011&#8242; )<br
/> server_format_date ( &#8217;04-03-2011&#8242; )</p><p> server_format_date ( &#8217;4311&#8242; )<br
/> server_format_date ( &#8217;40311&#8242; )<br
/> server_format_date ( &#8217;040311&#8242; )</p><p> server_format_date ( &#8217;4032011&#8242; )<br
/> server_format_date ( &#8217;04032011&#8242; )</p> ]]></content:encoded> </item> <item><title>By: Suresh Nambiar</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-7099</link> <dc:creator>Suresh Nambiar</dc:creator> <pubDate>Sun, 24 Apr 2011 14:39:46 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-7099</guid> <description>def server_format_date ( strdate )
strdt = strdate.chomp
case strdt.gsub(/\D/,&quot;-&quot;)
when /\d{8}/ then Date.strptime(strdt, &quot;%d%m%Y&quot;)
when /\d{7}/ then Date.strptime(&#039;0&#039; + strdt, &quot;%d%m%Y&quot;)
when /\d{6}/ then Date.strptime(strdt, &quot;%d%m%y&quot;)
when /\d{5}/ then Date.strptime(&#039;0&#039; + strdt, &quot;%d%m%y&quot;)
when /\d{4}/ then Date.strptime(strdt[0] + &quot;-&quot; + strdt[1] + &quot;-&quot; + strdt[2..3], &quot;%d-%m-%y&quot;)
when /\d{2}-\d{2}-\d{4}/ then Date.strptime(strdt, &quot;%d-%m-%Y&quot;)
when /\d{2}-\d{2}-\d{2}/ then Date.strptime(strdt, &quot;%d-%m-%y&quot;)
when /\d{4}-\d{2}-\d{2}/ then Date.strptime(strdt, &quot;%Y-%m-%d&quot;)
end
end
Test Cases :-
server_format_date ( &#039;2011-3-4&#039; )
server_format_date ( &#039;2011-3-04&#039; )
server_format_date ( &#039;2011-03-4&#039; )
server_format_date ( &#039;2011-03-04&#039; )
server_format_date ( &#039;4-3-2011&#039; )
server_format_date ( &#039;04-3-2011&#039; )
server_format_date ( &#039;4-03-2011&#039; )
server_format_date ( &#039;04-03-2011&#039; )
server_format_date ( &#039;4311&#039; )
server_format_date ( &#039;40311&#039; )
server_format_date ( &#039;040311&#039; )
server_format_date ( &#039;4032011&#039; )
server_format_date ( &#039;04032011&#039; )</description> <content:encoded><![CDATA[<p>def server_format_date ( strdate )<br
/> strdt = strdate.chomp<br
/> case strdt.gsub(/\D/,&#8221;-&#8221;)<br
/> when /\d{8}/ then Date.strptime(strdt, &#8220;%d%m%Y&#8221;)<br
/> when /\d{7}/ then Date.strptime(&#8217;0&#8242; + strdt, &#8220;%d%m%Y&#8221;)<br
/> when /\d{6}/ then Date.strptime(strdt, &#8220;%d%m%y&#8221;)<br
/> when /\d{5}/ then Date.strptime(&#8217;0&#8242; + strdt, &#8220;%d%m%y&#8221;)<br
/> when /\d{4}/ then Date.strptime(strdt[0] + &#8220;-&#8221; + strdt[1] + &#8220;-&#8221; + strdt[2..3], &#8220;%d-%m-%y&#8221;)<br
/> when /\d{2}-\d{2}-\d{4}/ then Date.strptime(strdt, &#8220;%d-%m-%Y&#8221;)<br
/> when /\d{2}-\d{2}-\d{2}/ then Date.strptime(strdt, &#8220;%d-%m-%y&#8221;)<br
/> when /\d{4}-\d{2}-\d{2}/ then Date.strptime(strdt, &#8220;%Y-%m-%d&#8221;)<br
/> end<br
/> end</p><p>Test Cases :-</p><p> server_format_date ( &#8217;2011-3-4&#8242; )<br
/> server_format_date ( &#8217;2011-3-04&#8242; )<br
/> server_format_date ( &#8217;2011-03-4&#8242; )<br
/> server_format_date ( &#8217;2011-03-04&#8242; )</p><p> server_format_date ( &#8217;4-3-2011&#8242; )<br
/> server_format_date ( &#8217;04-3-2011&#8242; )<br
/> server_format_date ( &#8217;4-03-2011&#8242; )<br
/> server_format_date ( &#8217;04-03-2011&#8242; )</p><p> server_format_date ( &#8217;4311&#8242; )<br
/> server_format_date ( &#8217;40311&#8242; )<br
/> server_format_date ( &#8217;040311&#8242; )</p><p> server_format_date ( &#8217;4032011&#8242; )<br
/> server_format_date ( &#8217;04032011&#8242; )</p> ]]></content:encoded> </item> <item><title>By: Chris</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-7027</link> <dc:creator>Chris</dc:creator> <pubDate>Sat, 12 Mar 2011 03:56:21 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-7027</guid> <description>Thanks, dude! From problem to solution within 30 seconds of the google.  Thanks!</description> <content:encoded><![CDATA[<p>Thanks, dude! From problem to solution within 30 seconds of the google.  Thanks!</p> ]]></content:encoded> </item> <item><title>By: Mitch</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-6741</link> <dc:creator>Mitch</dc:creator> <pubDate>Mon, 13 Dec 2010 19:48:10 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-6741</guid> <description>Of course, this means that the case statement is linear in time rather that constant as it would be in other languages.  That&#039;s the original point of case statements, after all.</description> <content:encoded><![CDATA[<p>Of course, this means that the case statement is linear in time rather that constant as it would be in other languages.  That&#8217;s the original point of case statements, after all.</p> ]]></content:encoded> </item> <item><title>By: given/when &#8211; the Perl switch statement &#171; transfixed but not dead!</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-6124</link> <dc:creator>given/when &#8211; the Perl switch statement &#171; transfixed but not dead!</dc:creator> <pubDate>Mon, 30 Aug 2010 20:13:25 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-6124</guid> <description>[...] post was inspired by this nice &amp; straightforward blog article: How A Ruby Case Statement Works And What You Can Do With It. I&#8217;ve simply converted the Ruby code to Perl and added some so called insightful [...]</description> <content:encoded><![CDATA[<p>[...] post was inspired by this nice &amp; straightforward blog article: How A Ruby Case Statement Works And What You Can Do With It. I&#8217;ve simply converted the Ruby code to Perl and added some so called insightful [...]</p> ]]></content:encoded> </item> <item><title>By: Akhil Bansal</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-4727</link> <dc:creator>Akhil Bansal</dc:creator> <pubDate>Mon, 19 Apr 2010 10:34:27 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-4727</guid> <description>Interesting, I didn&#039;t knew it.</description> <content:encoded><![CDATA[<p>Interesting, I didn&#8217;t knew it.</p> ]]></content:encoded> </item> <item><title>By: smeally</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-3376</link> <dc:creator>smeally</dc:creator> <pubDate>Tue, 05 Jan 2010 00:06:32 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-3376</guid> <description>Hey there this is a great post</description> <content:encoded><![CDATA[<p>Hey there this is a great post</p> ]]></content:encoded> </item> <item><title>By: Comparing Equality (==, eql?, equal?) and Case Equality (===) in Ruby &#8211; Refactoring Thoughts</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-3349</link> <dc:creator>Comparing Equality (==, eql?, equal?) and Case Equality (===) in Ruby &#8211; Refactoring Thoughts</dc:creator> <pubDate>Wed, 09 Dec 2009 05:45:20 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-3349</guid> <description>[...] which is not the same as &#8220;==&#8221;, what&#8217;s difference? See below explainations: http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/ [...]</description> <content:encoded><![CDATA[<p>[...] which is not the same as &#8220;==&#8221;, what&#8217;s difference? See below explainations: <a
href="http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/" rel="nofollow">http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/</a> [...]</p> ]]></content:encoded> </item> <item><title>By: Kai&#8217;s daily tech #28 &#8230; &#124; Kai Richard König</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-2646</link> <dc:creator>Kai&#8217;s daily tech #28 &#8230; &#124; Kai Richard König</dc:creator> <pubDate>Fri, 04 Sep 2009 20:07:29 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-2646</guid> <description>[...] How A Ruby Case Statement Works And What You Can Do With It [...]</description> <content:encoded><![CDATA[<p>[...] How A Ruby Case Statement Works And What You Can Do With It [...]</p> ]]></content:encoded> </item> <item><title>By: Dew Drop &#8211; August 25, 2009 &#124; Alvin Ashcraft's Morning Dew</title><link>http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/comment-page-1/#comment-2299</link> <dc:creator>Dew Drop &#8211; August 25, 2009 &#124; Alvin Ashcraft's Morning Dew</dc:creator> <pubDate>Tue, 25 Aug 2009 12:54:00 +0000</pubDate> <guid
isPermaLink="false">http://www.skorks.com/?p=1082#comment-2299</guid> <description>[...] How A Ruby Case Statement Works And What You Can Do With It (Alan Skorkin) [...]</description> <content:encoded><![CDATA[<p>[...] How A Ruby Case Statement Works And What You Can Do With It (Alan Skorkin) [...]</p> ]]></content:encoded> </item> </channel> </rss>
