Class: CookbookBumper::Version
- Inherits:
-
Object
- Object
- CookbookBumper::Version
- Defined in:
- lib/cookbook_bumper/version.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #bump ⇒ Object
- #exact ⇒ Object
-
#initialize(ver_string) ⇒ Version
constructor
A new instance of Version.
- #parse(ver_string) ⇒ Object
- #to_s ⇒ Object
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 |
#bump ⇒ Object
22 23 24 |
# File 'lib/cookbook_bumper/version.rb', line 22 def bump @patch += 1 end |
#exact ⇒ Object
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_s ⇒ Object
26 27 28 |
# File 'lib/cookbook_bumper/version.rb', line 26 def to_s [@major, @minor, @patch].join('.') end |