Class: Net::SSH::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/net/ssh/version.rb

Overview

A class for describing the current version of a library. The version consists of three parts: the major number, the minor number, and the tiny (or patch) number.

Two Version instances may be compared, so that you can test that a version of a library is what you require:

require 'net/ssh/version'

if Net::SSH::Version::CURRENT < Net::SSH::Version[2,1,0]
  abort "your software is too old!"
end

Constant Summary collapse

MAJOR =

The major component of this version of the Net::SSH library

6
MINOR =

The minor component of this version of the Net::SSH library

3
TINY =

The tiny component of this version of the Net::SSH library

1
PRE =

The prerelease component of this version of the Net::SSH library nil allowed

nil
CURRENT =

The current version of the Net::SSH library as a Version instance

new(*[MAJOR, MINOR, TINY, PRE].compact)
STRING =

The current version of the Net::SSH library as a String

CURRENT.to_s

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, tiny, pre = nil) ⇒ Version

Create a new Version object with the given components.



29
30
31
# File 'lib/net/ssh/version.rb', line 29

def initialize(major, minor, tiny, pre = nil)
  @major, @minor, @tiny, @pre = major, minor, tiny, pre
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



26
27
28
# File 'lib/net/ssh/version.rb', line 26

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



26
27
28
# File 'lib/net/ssh/version.rb', line 26

def minor
  @minor
end

#tinyObject (readonly)

Returns the value of attribute tiny.



26
27
28
# File 'lib/net/ssh/version.rb', line 26

def tiny
  @tiny
end

Class Method Details

.[](major, minor, tiny, pre = nil) ⇒ Object

A convenience method for instantiating a new Version instance with the given major, minor, and tiny components.



22
23
24
# File 'lib/net/ssh/version.rb', line 22

def self.[](major, minor, tiny, pre = nil)
  new(major, minor, tiny, pre)
end

Instance Method Details

#<=>(version) ⇒ Object

Compare this version to the given version object.



34
35
36
# File 'lib/net/ssh/version.rb', line 34

def <=>(version)
  to_i <=> version.to_i
end

#to_iObject

Converts this version to a canonical integer that may be compared against other version objects.



46
47
48
# File 'lib/net/ssh/version.rb', line 46

def to_i
  @to_i ||= @major * 1_000_000 + @minor * 1_000 + @tiny
end

#to_sObject

Converts this version object to a string, where each of the three version components are joined by the ‘.’ character. E.g., 2.0.0.



40
41
42
# File 'lib/net/ssh/version.rb', line 40

def to_s
  @to_s ||= [@major, @minor, @tiny, @pre].compact.join(".")
end