snex
4/30/2009 8:43:00 PM
On Apr 29, 2:24 pm, Todd Benson <caduce...@gmail.com> wrote:
> On Wed, Apr 29, 2009 at 2:21 PM, Todd Benson <caduce...@gmail.com> wrote:
> > On Wed, Apr 29, 2009 at 2:03 PM, Rob Redmon <rob.webina...@gmail.com> wrote:
>
> >> I have an ActiveRecord find result. An element's contents look like:
>
> >> irb(main):090:0> results[0]
> >> => #<InventoryHour id: 47475, observation_time: "2008-01-01 00:00:00",
> >> station_id: 6, extension_id: 22, disk: 4, archive: 0, updated_on:
> >> "2009-04-15 15:57:16">
>
> >> The class of "observation_time" is:
> >> results[0].observation_time.class
> >> => Time
>
> >> What I'd like to do is find those elements which match on a particular
> >> range of "observation_time". I'm used to Matlab and IDL programming
> >> where one just does something like this:
>
> >> indices = where( results.observation_time >= "2008-1-1" and
> >> results.observation_time < "2009-1-1" )
>
> >> What's the ruby way? Obviously, I can't use Array.include? but
> >> something like that would be nice.
>
> > Depends. This might work (just an example)...
>
> > d = Time.now
> > e = Time.now + 1
> > f = Time.now + 2
> > (d..f).include? e
> > => true
>
> beware, though, since (d...e).include?(e) is false, but
> (d...e).include?(d) is true.
>
> Todd
shouldnt you do this kind of filtering on the ActiveRecord#find call?