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.
398 399 400 401 |
# File 'lib/t2-server/server.rb', line 398 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.
438 439 440 441 442 443 444 445 446 447 |
# File 'lib/t2-server/server.rb', line 438 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
422 423 424 425 426 427 428 429 |
# File 'lib/t2-server/server.rb', line 422 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.
407 408 409 |
# File 'lib/t2-server/server.rb', line 407 def to_s @string end |