title: ruby comparison of time and variable
body: <p>I have two models, being an Employee and a WorkingPattern. An instance of an Employee belongs_to an Working Pattern. </p>
  
  <p>The Working Pattern looks like this</p>
  
  <pre><code>        :id =&gt; :integer,
        :name =&gt; :string,
         :mon =&gt; :boolean,
         :tue =&gt; :boolean,
         :wed =&gt; :boolean,
         :thu =&gt; :boolean,
         :fri =&gt; :boolean,
         :sat =&gt; :boolean,
         :sun =&gt; :boolean
  </code></pre>
  
  <p>I need to know if an Employee should be at work today. So, if today is a Tuesday and that employee's working pattern record reports that :tue = true then return true, etc. I don't have the option of renaming the fields on the WorkingPattern model to match the days names. </p>
  
  <p>I know that </p>
  
  <pre><code>Time.now.strftime("%A")
  </code></pre>
  
  <p>will return the name of the day. Then I figured out I can get the first 3 characters of the string by doing</p>
  
  <pre><code>Time.now.strftime("%A")[0,3]
  </code></pre>
  
  <p>so now I have "Tue" returned as a string. Add in a downcase</p>
  
  <pre><code>Time.now.strftime("%A")[0,3].downcase
  </code></pre>
  
  <p>and now I have "tue", which matches the symbol for :tue on the WorkingPattern.</p>
  
  <p>Now I need a way of checking the string against the correct day, ideally in a manner that doesn't mean 7 queries against the database for each employee!</p>
  
  <p>Can anyone advise?</p>