Class: Vump::Semver
- Inherits:
-
Object
- Object
- Vump::Semver
- Defined in:
- lib/vump/semver/semver.rb
Instance Attribute Summary collapse
-
#build ⇒ Object
Returns the value of attribute build.
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#patch ⇒ Object
Returns the value of attribute patch.
-
#pre ⇒ Object
Returns the value of attribute pre.
Instance Method Summary collapse
- #bump(what) ⇒ Object
- #bump_major ⇒ Object
- #bump_minor ⇒ Object
- #bump_patch ⇒ Object
-
#initialize(string = nil) ⇒ Semver
constructor
A new instance of Semver.
- #load(string) ⇒ Object
- #reset(what) ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(string = nil) ⇒ Semver
Returns a new instance of Semver.
5 6 7 8 9 |
# File 'lib/vump/semver/semver.rb', line 5 def initialize(string = nil) @pre = @build = false @major = @minor = @patch = 0 load string if string end |
Instance Attribute Details
#build ⇒ Object
Returns the value of attribute build.
3 4 5 |
# File 'lib/vump/semver/semver.rb', line 3 def build @build end |
#major ⇒ Object
Returns the value of attribute major.
3 4 5 |
# File 'lib/vump/semver/semver.rb', line 3 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
3 4 5 |
# File 'lib/vump/semver/semver.rb', line 3 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
3 4 5 |
# File 'lib/vump/semver/semver.rb', line 3 def patch @patch end |
#pre ⇒ Object
Returns the value of attribute pre.
3 4 5 |
# File 'lib/vump/semver/semver.rb', line 3 def pre @pre end |
Instance Method Details
#bump(what) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vump/semver/semver.rb', line 53 def bump(what) case what when :patch bump_patch when :minor bump_minor when :major bump_major end end |
#bump_major ⇒ Object
48 49 50 51 |
# File 'lib/vump/semver/semver.rb', line 48 def bump_major reset :@minor @major += 1 end |
#bump_minor ⇒ Object
43 44 45 46 |
# File 'lib/vump/semver/semver.rb', line 43 def bump_minor reset :@patch @minor += 1 end |
#bump_patch ⇒ Object
38 39 40 41 |
# File 'lib/vump/semver/semver.rb', line 38 def bump_patch reset :@pre @patch += 1 end |
#load(string) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vump/semver/semver.rb', line 11 def load(string) # <numeral>[-<pre>][+<build>] version, @pre, @build = string .match(/([\d\.]+)(?:\-)?([^\+]*)(?:\+)?(.*)?/) .to_a .drop(1) # <numeral>:= <major>.<minor>.<patch> @major, @minor, @patch = version .match(/(\d+)\.(\d+)\.(\d+)/) .to_a .drop(1) .map(&:to_i) end |
#reset(what) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/vump/semver/semver.rb', line 29 def reset(what) levels = i[@build @pre @patch @minor @major] # tag to false, version to 0 reset_to = i[@build @pre].include?(what) ? false : 0 instance_variable_set(what, reset_to) # reset lesser sections reset levels[levels.index(what) - 1] if levels.index(what) != 0 end |
#to_s ⇒ Object
64 65 66 67 68 69 |
# File 'lib/vump/semver/semver.rb', line 64 def to_s str = "#{@major}.#{@minor}.#{@patch}" str << "-#{@pre}" if @pre && @pre != '' str << "+#{@build}" if @build && @build != '' str end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/vump/semver/semver.rb', line 25 def valid? [@major, @minor, @patch].all? { |v| v.is_a?(Numeric) } end |