# Finding software versions below a given version

**URL:** <https://www.ruby-forum.com/t/finding-software-versions-below-a-given-version/151377>\
**Category:** Rails\
**Created:** [October 20, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/finding-software-versions-below-a-given-version/151377 "2008-10-20T20:52:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trptcolin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@trptcolin](https://www.ruby-forum.com/u/trptcolin)\
**Post date:** [October 20, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/finding-software-versions-below-a-given-version/151377/1 "2008-10-20T20:52:24Z")

</div>

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?
