Class: Releasetool::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/releasetool/version.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ident) ⇒ Version

Returns a new instance of Version.



7
8
9
10
11
# File 'lib/releasetool/version.rb', line 7

def initialize(ident)
  raise "Not a valid version identifier: #{ident.inspect}" unless ident.is_a?(String)

  @ident = ident
end

Instance Attribute Details

#identObject (readonly)

Returns the value of attribute ident.



5
6
7
# File 'lib/releasetool/version.rb', line 5

def ident
  @ident
end

Class Method Details

.normalized(major, minor, patch) ⇒ Object



45
46
47
# File 'lib/releasetool/version.rb', line 45

def self.normalized(major, minor, patch)
  new("v#{major}.#{minor}.#{patch}")
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/releasetool/version.rb', line 41

def ==(other)
  other.is_a?(Releasetool::Version) && ident == other.ident
end

#next_majorObject



21
22
23
# File 'lib/releasetool/version.rb', line 21

def next_major
  self.class.normalized(incremented(segments[0]), 0, 0)
end

#next_minorObject



17
18
19
# File 'lib/releasetool/version.rb', line 17

def next_minor
  self.class.normalized(segments[0], incremented(segments[1]), 0)
end

#next_patchObject



13
14
15
# File 'lib/releasetool/version.rb', line 13

def next_patch
  self.class.normalized(segments[0], segments[1], incremented(segments[2]))
end

#to_sObject



25
26
27
28
29
30
31
# File 'lib/releasetool/version.rb', line 25

def to_s
  if @ident[0] == "v"
    @ident
  else
    "v#{@ident}"
  end
end

#to_s_without_vObject



33
34
35
36
37
38
39
# File 'lib/releasetool/version.rb', line 33

def to_s_without_v
  if @ident[0] == "v"
    @ident[1..-1]
  else
    @ident
  end
end