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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Colin J. (Guest)
on 2008-10-20 22: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
hash:

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


I can do something crappy like this:

@versions.select { |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])
or
  (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.