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 = version_input.dup
  unless version_input.respond_to?(:to_ary)
    version_components = version_input.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.



66
67
68
# File 'lib/version-manager/release_version.rb', line 66

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



66
67
68
# File 'lib/version-manager/release_version.rb', line 66

def minor
  @minor
end

#partsObject (readonly)

Returns the value of attribute parts.



66
67
68
# File 'lib/version-manager/release_version.rb', line 66

def parts
  @parts
end

#patchObject (readonly)

Returns the value of attribute patch.



66
67
68
# File 'lib/version-manager/release_version.rb', line 66

def patch
  @patch
end

#specialObject (readonly)

Returns the value of attribute special.



66
67
68
# File 'lib/version-manager/release_version.rb', line 66

def special
  @special
end

Class Method Details

.valid?(version) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#<=>(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



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

def bump_major
  @major += 1
  @minor = 0
  @patch = 0
  recalculate_parts
end

#bump_minorObject



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

def bump_minor
  @minor += 1
  @patch = 0
  recalculate_parts
end

#bump_patchObject



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

def bump_patch
  @patch += 1
  recalculate_parts
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