Class: VersionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/version_manager.rb

Overview

Manages software versions with Major, Minor, and Patch components.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major = 0, minor = 0, patch = 0) ⇒ VersionManager

Initializes a new instance of VersionManager.

Parameters:

  • major (Integer, String) (defaults to: 0)

    The major version or a string in the format "major.minor.patch".

  • minor (Integer) (defaults to: 0)

    The minor version (optional if major is a string).

  • patch (Integer) (defaults to: 0)

    The patch version (optional if major is a string).



12
13
14
15
16
17
18
19
20
# File 'lib/utils/version_manager.rb', line 12

def initialize(major = 0, minor = 0, patch = 0)
  if major.is_a?(String)
    parse_version_string(major)
  else
    @major = major
    @minor = minor
    @patch = patch
  end
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



5
6
7
# File 'lib/utils/version_manager.rb', line 5

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



5
6
7
# File 'lib/utils/version_manager.rb', line 5

def minor
  @minor
end

#patchObject (readonly)

Returns the value of attribute patch.



5
6
7
# File 'lib/utils/version_manager.rb', line 5

def patch
  @patch
end

Instance Method Details

#increment_majorObject

Increments the major version and resets minor and patch to 0.



23
24
25
26
27
# File 'lib/utils/version_manager.rb', line 23

def increment_major
  @major += 1
  @minor = 0
  @patch = 0
end

#increment_minorObject

Increments the minor version and resets patch to 0.



30
31
32
33
# File 'lib/utils/version_manager.rb', line 30

def increment_minor
  @minor += 1
  @patch = 0
end

#increment_patchObject

Increments the patch version.



36
37
38
# File 'lib/utils/version_manager.rb', line 36

def increment_patch
  @patch += 1
end

#to_sString

Returns the version as a string in the format "major.minor.patch".

Returns:

  • (String)

    The formatted version.



43
44
45
# File 'lib/utils/version_manager.rb', line 43

def to_s
  "#{@major}.#{@minor}.#{@patch}"
end