Class: Bump::VersionNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/bump/domain/version_number.rb

Overview

The version number model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, patch, preid = nil) ⇒ VersionNumber

Returns a new instance of VersionNumber.

Parameters:

  • major (Integer)
  • minor (Integer)
  • patch (Integer)
  • preid (String, nil) (defaults to: nil)


10
11
12
13
14
15
# File 'lib/bump/domain/version_number.rb', line 10

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

Instance Attribute Details

#preid=(value) ⇒ Object (writeonly)

Sets the attribute preid

Parameters:

  • value

    the value to set the attribute preid to.



4
5
6
# File 'lib/bump/domain/version_number.rb', line 4

def preid=(value)
  @preid = value
end

Instance Method Details

#bump(level) ⇒ void

This method returns an undefined value.

Bumps the version at the given level

Parameters:

  • level (Symbol)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bump/domain/version_number.rb', line 21

def bump(level)
  case level
  when :major
    @major += 1
    @minor = 0
    @patch = 0
  when :minor
    @minor += 1
    @patch = 0
  when :patch
    @patch += 1
  end
  @preid = nil
end

#to_sString

Returns the string representation of the version

Returns:

  • (String)


38
39
40
41
42
43
44
# File 'lib/bump/domain/version_number.rb', line 38

def to_s
  label = @major.to_s + '.' + @minor.to_s + '.' + @patch.to_s

  label = label + '-' + @preid if @preid

  label
end