Class: VersionManager::ReleaseVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/version-manager/release_version.rb

Defined Under Namespace

Classes: IncorrentFormat

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*version_input) ⇒ ReleaseVersion

Returns a new instance of ReleaseVersion.



11
12
13
14
15
16
17
18
19
20
# File 'lib/version-manager/release_version.rb', line 11

def initialize(*version_input)
  version_components = Array(version_input.dup.flatten)
  if version_components.size == 1
    version_components = version_components.first.scan(/(\d+)\.{1}(\d+)\.?(\d*)(?:--(\w+))?/).flatten
    raise ArgumentError, 'Incorrect version format' if version_components.all?(&:nil?) || version_components.empty?
  end
  @major, @minor, @patch = version_components[0..2].map(&:to_i)
  @special = version_components[3]
  recalculate_parts
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



64
65
66
# File 'lib/version-manager/release_version.rb', line 64

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



64
65
66
# File 'lib/version-manager/release_version.rb', line 64

def minor
  @minor
end

#partsObject (readonly)

Returns the value of attribute parts.



64
65
66
# File 'lib/version-manager/release_version.rb', line 64

def parts
  @parts
end

#patchObject (readonly)

Returns the value of attribute patch.



64
65
66
# File 'lib/version-manager/release_version.rb', line 64

def patch
  @patch
end

#specialObject (readonly)

Returns the value of attribute special.



64
65
66
# File 'lib/version-manager/release_version.rb', line 64

def special
  @special
end

Class Method Details

.valid?(version) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
# File 'lib/version-manager/release_version.rb', line 58

def self.valid?(version)
  new(version) && true
rescue ArgumentError
  false
end

Instance Method Details

#-(other_version) ⇒ Object



42
43
44
# File 'lib/version-manager/release_version.rb', line 42

def -(other_version)
  self.class.new(parts.zip(other_version.parts).map { |x, y| x - y })
end

#<=>(other_version) ⇒ Object



36
37
38
39
40
# File 'lib/version-manager/release_version.rb', line 36

def <=>(other_version)
  parts.zip(other_version.parts).
    map { |this, other| this <=> other }.
    find { |res| res != 0 } || 0
end

#branchObject



32
33
34
# File 'lib/version-manager/release_version.rb', line 32

def branch
  VersionManager.options[:version_name].call(self)
end

#bump_majorObject



46
47
48
# File 'lib/version-manager/release_version.rb', line 46

def bump_major
  self.class.new(@major + 1, 0, 0)
end

#bump_minorObject



50
51
52
# File 'lib/version-manager/release_version.rb', line 50

def bump_minor
  self.class.new(@major, @minor + 1, 0)
end

#bump_patchObject



54
55
56
# File 'lib/version-manager/release_version.rb', line 54

def bump_patch
  self.class.new(@major, @minor, @patch + 1)
end

#short_versionObject



28
29
30
# File 'lib/version-manager/release_version.rb', line 28

def short_version
  [major, minor].map(&:to_i).join('.')
end

#to_strObject Also known as: to_s



22
23
24
25
# File 'lib/version-manager/release_version.rb', line 22

def to_str
  res = parts.map(&:to_i).join('.')
  [res, special].compact.join('--')
end