Class: Mmi::Semver

Inherits:
Object
  • Object
show all
Defined in:
lib/mmi/semver.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major, minor, patch) ⇒ Semver

Returns a new instance of Semver.



7
8
9
10
11
# File 'lib/mmi/semver.rb', line 7

def initialize(major, minor, patch)
	self.major = major
	self.minor = minor
	self.patch = patch
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



3
4
5
# File 'lib/mmi/semver.rb', line 3

def major
  @major
end

#minorObject

Returns the value of attribute minor.



4
5
6
# File 'lib/mmi/semver.rb', line 4

def minor
  @minor
end

#patchObject

Returns the value of attribute patch.



5
6
7
# File 'lib/mmi/semver.rb', line 5

def patch
  @patch
end

Class Method Details

.parse(version) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/mmi/semver.rb', line 13

def self.parse(version)
	if (m = /\A(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)\z/.match(version.strip))
		new(m[:major].to_i, m[:minor].to_i, m[:patch].to_i)
	else
		raise "Version string not in valid format: #{version.inspect}"
	end
end