<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users90</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/90" rel="self"/>
  <title>anshkakashi</title>
  <updated>Tue Oct 02 12:47:23 -0700 2007</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code46</id>
    <published>2007-10-02T12:47:23-07:00</published>
    <updated>2010-03-09T16:18:34-08:00</updated>
    <title>[Ruby] Accept Language Array</title>
    <content type="html">&lt;p&gt;This is some rails code where I want to take the HTTP_ACCEPT_LANGUAGE header and match it to an array of supported languages. It looks awful here, I know there must be a better way to do this, right?&lt;/p&gt;

&lt;pre&gt;SUPPORTED_LANGUAGES = [[&amp;quot;English&amp;quot;, &amp;quot;en&amp;quot;], [&amp;quot;German&amp;quot;, &amp;quot;de&amp;quot;]]
# request.env[&amp;quot;HTTP_ACCEPT_LANGUAGE&amp;quot;] = &amp;quot;en-us,us;q=0.5&amp;quot;
@languages = request.env[&amp;quot;HTTP_ACCEPT_LANGUAGE&amp;quot;].split(';')[0].split(',')
# @languages = [&amp;quot;en-us&amp;quot;, &amp;quot;us&amp;quot;]
@languages.each { |lang|
  @match = lang[0..1] if SUPPORTED_LANGUAGES.flatten.include?(lang[0..1])
}
# @match = &amp;quot;en&amp;quot;
if @match
  @language = SUPPORTED_LANGUAGES.find_all { |x| x[1] == @match }[0][0]
else
  @language = SUPPORTED_LANGUAGES[0][0]
end
# @language = &amp;quot;English&amp;quot;
&lt;/pre&gt;</content>
    <author>
      <name>anshkakashi</name>
      <email>anshkakashi@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/46-accept-language-array" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor138</id>
    <published>2007-09-30T15:14:25-07:00</published>
    <title>[Ruby] On compound interest</title>
    <content type="html">&lt;p&gt;Here is the same thing, a bit shorter.
&lt;/p&gt;

&lt;pre&gt;cap_growth = 5

v = @property.current_value

8.times do
  puts v += v/ 100 * cap_growth
end&lt;/pre&gt;</content>
    <author>
      <name>anshkakashi</name>
      <email>anshkakashi@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/34-compound-interest/refactors/138" rel="alternate"/>
  </entry>
</feed>

