Class: Semver
- Inherits:
-
Object
- Object
- Semver
- Defined in:
- lib/smart_semver/semver.rb
Instance Attribute Summary collapse
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #increment(current, which) ⇒ Object
-
#initialize(version = nil) ⇒ Semver
constructor
A new instance of Semver.
- #reset(current, which) ⇒ Object
- #valid? ⇒ Boolean
Methods included from Release
Methods included from Rc
Methods included from Beta
Methods included from Dev
Methods included from Major
Methods included from Minor
Methods included from Patch
Constructor Details
#initialize(version = nil) ⇒ Semver
Returns a new instance of Semver.
20 21 22 |
# File 'lib/smart_semver/semver.rb', line 20 def initialize(version=nil) @version = version ||= '0.1.0' end |
Instance Attribute Details
#version ⇒ Object
Returns the value of attribute version.
18 19 20 |
# File 'lib/smart_semver/semver.rb', line 18 def version @version end |
Instance Method Details
#increment(current, which) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/smart_semver/semver.rb', line 38 def increment(current, which) version, flag = current.split '-' v = version.split '.' v[which] = v[which].to_i + 1 [v.join('.'), flag].compact.join '-' end |
#reset(current, which) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/smart_semver/semver.rb', line 45 def reset(current, which) version, flag = current.split '-' v = version.split '.' which.each do |part| v[part] = 0 end [v.join('.'), flag].compact.join '-' end |
#valid? ⇒ Boolean
54 55 56 57 |
# File 'lib/smart_semver/semver.rb', line 54 def valid? pattern = /^\d+\.\d+\.\d+(\-(dev|beta|rc\d+))?$/ version =~ pattern ? true : false end |