class Cpe23::Version
Attributes
parts[R]
Public Class Methods
new(str)
click to toggle source
# File lib/cpe23/version_wildcard.rb, line 8 def initialize(str) @parts = str.split('.') wildcard_index = @parts.index '*' if wildcard_index.nil? @parts << '*' elsif wildcard_index < @parts.size - 1 raise 'Wildcard must be at the end of a version' end end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/cpe23/version_wildcard.rb, line 18 def <=>(other) unless other.is_a? Version begin other = Version.new(other) rescue StandardError return nil end end @parts.zip(other.parts).each do |a, b| break if a == '*' || b == '*' # Compare parts numerically if they are numeric if int?(a) && int?(b) a = a.to_i b = b.to_i end return -1 if a.to_i < b.to_i return 1 if a.to_i > b.to_i end 0 end
Private Instance Methods
int?(str)
click to toggle source
# File lib/cpe23/version_wildcard.rb, line 42 def int?(str) true if Integer(str) rescue StandardError false end