class WolfTrans::Version
Version
; represents a major/minor version scheme
Attributes
major[RW]
minor[RW]
Public Class Methods
new(major: nil, minor: nil, flt: nil, str: nil)
click to toggle source
# File lib/wolftrans.rb, line 41 def initialize(major: nil, minor: nil, flt: nil, str: nil) # See if we need to parse from a string if flt string = flt.to_s elsif str string = str else string = nil end # Extract major and minor numbers if string if match = string.match(/(\d+)\.(\d+)/) @major, @minor = match.captures.map { |s| s.to_i } else raise "could not parse version string '#{string}'" end elsif major && minor @major = major @minor = minor else @major = 0 @minor = 0 end end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/wolftrans.rb, line 71 def <=>(other) case other when Version return 0 if major == other.major && minor == other.minor return 1 if major > other.major || (major == other.major && minor >= other.minor) return -1 when String return self == Version.new(str = other) when Float return self == Version.new(flt = other) end return nil end
to_s()
click to toggle source
# File lib/wolftrans.rb, line 67 def to_s "#{@major}.#{@minor}" end