class Naturalsorter::Sorter
Public Class Methods
bigger?(a, b)
click to toggle source
# File lib/naturalsorter.rb, line 72 def self.bigger?(a, b) return false if a.eql?( b ) return false if Versioncmp.compare(a, b) == 0 newest = self.get_newest a, b newest.eql?( a ) end
bigger_or_equal?(a, b)
click to toggle source
# File lib/naturalsorter.rb, line 86 def self.bigger_or_equal?(a, b) return true if a.eql?(b) return true if Versioncmp.compare(a, b) == 0 newest = self.get_newest a, b newest.eql?(a) end
get_newest(a, b)
click to toggle source
# File lib/naturalsorter.rb, line 67 def self.get_newest(a, b) Versioncmp.replace_leading_vs a, b Sorter.get_newest_version(a, b) end
get_newest_version(first, second)
click to toggle source
# File lib/naturalsorter.rb, line 61 def self.get_newest_version(first, second) array = [first, second] array = array.sort { |a,b| Versioncmp.compare( a, b ) } array.last end
is_version_current?(version, newest_version)
click to toggle source
This is for the GEM notaiton ~> For example ~>1.1 fits 1.2 and 1.9 and 1.14 But not 2.0
# File lib/naturalsorter.rb, line 105 def self.is_version_current?(version, newest_version) version = version.gsub("~>", "") version = version.gsub(" " , "") versions = version.split(".") newests = newest_version.split(".") min_length = versions.size if newests.size < min_length min_length = newests.size end min_length = min_length - 2 if min_length < 0 min_length = 0 end (0..min_length).each do |z| ver = versions[z] cur = newests[z] if (cur > ver) return false end end if newests.size < versions.size ver = versions[min_length + 1] cur = newests[min_length + 1] if cur > ver return false end end true end
replace_minimum_stability(val)
click to toggle source
# File lib/naturalsorter.rb, line 135 def self.replace_minimum_stability val VersionTagRecognizer.remove_minimum_stability val end
smaller?(a, b)
click to toggle source
# File lib/naturalsorter.rb, line 79 def self.smaller?(a, b) return false if b.eql?( a ) return false if Versioncmp.compare(a, b) == 0 newest = self.get_newest a, b newest.eql?( b ) end
smaller_or_equal?(a, b)
click to toggle source
# File lib/naturalsorter.rb, line 93 def self.smaller_or_equal?(a, b) return true if a.eql?(b) return true if Versioncmp.compare(a, b) == 0 newest = self.get_newest a, b newest.eql?(b) end
sort(array, caseinsensitive = false , asc = true )
click to toggle source
# File lib/naturalsorter.rb, line 32 def self.sort(array, caseinsensitive = false , asc = true ) return array if (array.nil? || array.empty?) return array.sort { |a, b| Natcmp.natcmp(a, b, caseinsensitive) } if asc return array.sort { |a, b| Natcmp.natcmp(b, a, caseinsensitive) } end
sort_by_method(array, method, caseinsensitive = false, asc = true)
click to toggle source
'Natural order' sort for an array of objects.
# File lib/naturalsorter.rb, line 39 def self.sort_by_method(array, method, caseinsensitive = false, asc = true) return array if (array.nil? || array.empty? || array.length == 1) return array.sort { |a, b| Natcmp.natcmp( a.send(method), b.send(method), caseinsensitive) } if asc return array.sort { |a, b| Natcmp.natcmp(b.send(method), a.send(method), caseinsensitive) } end
sort_version(array, asc = true)
click to toggle source
# File lib/naturalsorter.rb, line 46 def self.sort_version(array, asc = true) return array if (array.nil? || array.empty? || array.length == 1) return array if (array[0].nil? || array[1].nil?) return array.sort { |a,b| Versioncmp.compare( a, b ) } if asc return array.sort { |a,b| Versioncmp.compare( b, a ) } end
sort_version_by_method(array, method, asc = true )
click to toggle source
# File lib/naturalsorter.rb, line 54 def self.sort_version_by_method(array, method, asc = true ) return array if (array.nil? || array.empty? || array.length == 1 ) return array.sort { |a,b| Versioncmp.compare(a.send(method), b.send(method)) } if asc return array.sort { |a,b| Versioncmp.compare(b.send(method), a.send(method)) } end