title: Is there a way to check crontab-like time segments in Ruby?
body: <p>I am trying to implement a job handler that works like this: every minute via cron, run a given job class. That job will then use some heuristics (like looking in a table) to see if it should proceed. One of those heuristics would be whether the current time matches the &quot;time pattern&quot; for that particular job type.</p>
  <p>The &quot;time pattern&quot; could be in a crontab-like format, or I may just leave it simple in terms of rounded &quot;chunks&quot; of time, like &quot;5 minutes&quot; or &quot;30 minutes&quot;.</p>
  <p>So what I'm wondering, if the job runs every minute and then needs to check &quot;am I on the 5 minute mark&quot;, how would I do that in Ruby?</p>
  <p>So at 1:42 it would run but it's not on the 5 minute mark, so it skips
  1:43 -&gt; not 5-minute
  1:44 -&gt; not 5-minute
  1:45 -&gt; yes, 5-minute, so it does something
  1:46 -&gt; not 5-minute
  etc.</p>
  <p>Basically I'm looking for some &quot;modulus&quot; functionality with a time amount.</p>
  <p>I could imagine wanting to do &quot;every 10 minutes&quot; or &quot;every 15 minutes&quot; and maybe even &quot;every 2 hours&quot; or &quot;every 12 hours&quot;.</p>
  <p>It's possible this is just a bad idea, but I thought I'd at least consider how this could be handled in Ruby.</p>
  <p>The reason I want to do this: I don't want the scheduler to have to know about the nuances of the jobs and whether they should actually run. I want it to just run a &quot;handler&quot; class that then figures out how frequently a given job should run based on other rules (thus the &quot;every X minutes&quot; bit).</p>
  <p>This would run in the context of Ruby on Rails so if there are Rails-specific ways to do this, that's fine too.</p>
  <p>Cheers!</p>