Forum: Ruby on Rails finding software versions below a given version

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7f682b58d31d5a5bea3cdbf48a615db4?d=identicon&s=25 Colin Jones (trptcolin)
on 2008-10-20 20:52
I know there must be a Rails way to do this. A little help?

I have 4 columns in the database (MySQL) holding application version
info (split from a delimited string like "2.6.50:1200" that always has
all parts).  I can sort it easily in the way I'm thinking:

@versions = Version.find(:all, :order => "app_major, app_minor,
app_maintenance, app_build")

But I need to be able to grab all the versions that are BELOW a given
version (which may or may not itself exist in the database).  So, if I
have the current version (or whatever version I want to search) in a

current_app = { :major => 2, :minor => 60, :maintenance => 50, :build =>
1200 }

I can do something crappy like this: { |d|
  d.app_major < current_app[:major] or
  (d.app_major = current_app[:major] and d.app_minor <
current_app[:minor]) or
  (d.app_major = current_app[:major] and d.app_minor =
current_app[:minor] and d.app_maintenance < current_app[:maintenance])
  (d.app_major = current_app[:major] and d.app_minor =
current_app[:minor] and d.app_maintenance = current_app[:maintenance]
and d.app_build < current_app[:build])

but this seems simplistic and not very Rubyish.  There has to be a
simple way, right?
This topic is locked and can not be replied to.