class T2Server::Server::Version
Represents a Taverna Server
version number in a way that can be compared to other version numbers or strings.
This class mixes in Comparable so all the usual comparison operators work as expected.
Public Class Methods
new(version_string) → Version
click to toggle source
Create a new Version
object from the supplied version string.
# File lib/t2-server/server.rb 397 def initialize(version) 398 @string = parse_version(version) 399 @array = [] 400 end
Public Instance Methods
version <=> other → -1, 0 or +1
click to toggle source
Returns -1, 0 or +1 depending of whether version
is less than, equal to or greater than other
.
This is the basis for the tests in Comparable.
# File lib/t2-server/server.rb 437 def <=>(other) 438 other = Version.new(other) if other.instance_of?(String) 439 self.to_a.zip(other.to_a).each do |c| 440 comp = c[0] <=> c[1] 441 return comp unless comp == 0 442 end 443 444 # If we get here then we know we have equal version numbers. 445 0 446 end
to_a → Array
click to toggle source
Convert this Version
object into an array of numbers representing the components of the version number. The order of the components is:
-
Major
-
Minor
-
Patch
For example:
Version.new("2.5.1").to_a == [2, 5, 1]
# File lib/t2-server/server.rb 421 def to_a 422 if @array.empty? 423 comps = @string.split(".") 424 @array = comps.map { |v| v.to_i } 425 end 426 427 @array 428 end
to_s → String
click to toggle source
Convert this Version
object back into a String.
# File lib/t2-server/server.rb 406 def to_s 407 @string 408 end
Private Instance Methods
parse_version(version)
click to toggle source
# File lib/t2-server/server.rb 450 def parse_version(version) 451 # Remove extra version tags if present. 452 version.gsub!("-SNAPSHOT", "") 453 version.gsub!(/alpha[0-9]*/, "") 454 455 # Add .0 if we only have a major and minor component. 456 if version.split(".").length == 2 457 version += ".0" 458 end 459 460 version 461 end