Class: T2Server::Server::Version
- Inherits:
-
Object
- Object
- T2Server::Server::Version
- Includes:
- Comparable
- Defined in:
- lib/t2-server/server.rb
Overview
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.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
:call-seq: version <=> other -> -1, 0 or +1.
-
#initialize(version) ⇒ Version
constructor
:call-seq: new(version_string) -> Version.
-
#to_a ⇒ Object
:call-seq: to_a -> Array.
-
#to_s ⇒ Object
:call-seq: to_s -> String.
Constructor Details
#initialize(version) ⇒ Version
:call-seq:
new(version_string) -> Version
Create a new Version object from the supplied version string.
397 398 399 400 |
# File 'lib/t2-server/server.rb', line 397 def initialize(version) @string = parse_version(version) @array = [] end |
Instance Method Details
#<=>(other) ⇒ Object
:call-seq:
version <=> other -> -1, 0 or +1
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.
437 438 439 440 441 442 443 444 445 446 |
# 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 ⇒ Object
:call-seq:
to_a -> Array
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]
421 422 423 424 425 426 427 428 |
# 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 ⇒ Object
:call-seq:
to_s -> String
Convert this Version object back into a String.
406 407 408 |
# File 'lib/t2-server/server.rb', line 406 def to_s @string end |