Class: BrocadeAPIClient::APIVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/BrocadeAPIClient/apiversion.rb

Overview

Class for checking supported API versions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, patch) ⇒ APIVersion

Returns a new instance of APIVersion.



16
17
18
19
20
# File 'lib/BrocadeAPIClient/apiversion.rb', line 16

def initialize(major, minor, patch)
  @major = major
  @minor = minor
  @patch = patch
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



14
15
16
# File 'lib/BrocadeAPIClient/apiversion.rb', line 14

def major
  @major
end

#minorObject

Returns the value of attribute minor.



14
15
16
# File 'lib/BrocadeAPIClient/apiversion.rb', line 14

def minor
  @minor
end

#patchObject

Returns the value of attribute patch.



14
15
16
# File 'lib/BrocadeAPIClient/apiversion.rb', line 14

def patch
  @patch
end

Class Method Details

.parser(version) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/BrocadeAPIClient/apiversion.rb', line 37

def self.parser(version)
  version_array = version.split('.')
  validate(version_array)
  @major = version_array[0].to_i
  @minor = version_array[1].to_i
  @patch = version_array[2].to_i
  obj_v = APIVersion.new(@major, @minor, @patch)
  obj_v
end

.validate(version) ⇒ Object

Raises:

  • (BrocadeAPIClient::InvalidVersion)


33
34
35
# File 'lib/BrocadeAPIClient/apiversion.rb', line 33

def self.validate(version)
  raise BrocadeAPIClient::InvalidVersion if version.length != 3
end

Instance Method Details

#<=>(other) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/BrocadeAPIClient/apiversion.rb', line 22

def <=>(other)
  return -1 if major < other.major
  return 1 if major > other.major
  return -1 if minor < other.minor
  return 1 if minor > other.minor
  return -1 if patch < other.patch
  return 1 if patch > other.patch

  0
end