Module: TagComparer
Overview
A comparison class that can be used to compare version numbers for software projects
Constant Summary collapse
- VERSION_PREFIXES =
These are the allowed version prefixes at this time
{ 'rc' => 100, 'beta' => 99, 'b' => 99, 'alpha' => 98, 'a' => 98, 'v' => 1 # makes processing easier }
Instance Method Summary collapse
-
#get_latest(*args) ⇒ Object
Compares a list of version numbers and returns the latest one based on logical version numbering systems.
Instance Method Details
#get_latest(*args) ⇒ Object
Compares a list of version numbers and returns the latest one based on logical version numbering systems. Arguments can be arrays of strings or just strings.
Examples
get_latest(‘v1,’v2’) # returns ‘v2’ get_latest(‘v1.3.beta1’, ‘v1.3.beta2’) # returns ‘v1.3.beta2’ get_latest([‘v1.3.beta1’, ‘v1.3.rc1’, ‘v1.3.alpha1’]) # returns ‘v1.3.rc1’
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tag_comparer.rb', line 25 def get_latest(*args) = [] args.each do |a| if a.kind_of?(Array) .push(a) else .push(a) end end .flatten! latest_tag = .first .each do |tag| latest_tag = compare_items(latest_tag, tag) >= 0 ? latest_tag : tag end latest_tag end |