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, line 397
def initialize(version)
  @string = parse_version(version)
  @array = []
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, line 437
def <=>(other)
  other = Version.new(other) if other.instance_of?(String)
  self.to_a.zip(other.to_a).each do |c|
    comp = c[0] <=> c[1]
    return comp unless comp == 0
  end

  # If we get here then we know we have equal version numbers.
  0
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, line 421
def to_a
  if @array.empty?
    comps = @string.split(".")
    @array = comps.map { |v| v.to_i }
  end

  @array
end
to_s → String click to toggle source

Convert this Version object back into a String.

# File lib/t2-server/server.rb, line 406
def to_s
  @string
end