Class: CookbookBumper::Version

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

Instance Method Summary collapse

Constructor Details

#initialize(ver_string) ⇒ Version

Returns a new instance of Version.



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

def initialize(ver_string)
  @ver_string = ver_string
  @major, @minor, @patch = parse(ver_string)
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
# File 'lib/cookbook_bumper/version.rb', line 18

def ==(other)
  parse(self) == parse(other)
end

#bumpObject



22
23
24
# File 'lib/cookbook_bumper/version.rb', line 22

def bump
  @patch += 1
end

#exactObject



30
31
32
# File 'lib/cookbook_bumper/version.rb', line 30

def exact
  to_s.prepend('= ')
end

#parse(ver_string) ⇒ Object



12
13
14
15
16
# File 'lib/cookbook_bumper/version.rb', line 12

def parse(ver_string)
  ver_string.to_s.match(/(?<major>\d+)\.(?<minor>\d+)\.?(?<patch>\d*)/) do |v|
    [v[:major], v[:minor], v[:patch]].map(&:to_i)
  end
end

#to_sObject



26
27
28
# File 'lib/cookbook_bumper/version.rb', line 26

def to_s
  [@major, @minor, @patch].join('.')
end