Class: Ronan::SemanticVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/ronan/semantic_version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_str) ⇒ SemanticVersion

Returns a new instance of SemanticVersion.



5
6
7
8
9
10
11
# File 'lib/ronan/semantic_version.rb', line 5

def initialize(version_str)
  version_str.match(/(\d+)\.(\d+)\.(\d+)/) do |m|
    self.major = m[1].to_i
    self.minor = m[2].to_i
    self.patch = m[3].to_i
  end
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



3
4
5
# File 'lib/ronan/semantic_version.rb', line 3

def major
  @major
end

#minorObject

Returns the value of attribute minor.



3
4
5
# File 'lib/ronan/semantic_version.rb', line 3

def minor
  @minor
end

#patchObject

Returns the value of attribute patch.



3
4
5
# File 'lib/ronan/semantic_version.rb', line 3

def patch
  @patch
end

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
16
17
18
# File 'lib/ronan/semantic_version.rb', line 13

def <=>(other)
  result = self.major <=> other.major
  result = self.minor <=> other.minor if result == 0
  result = self.patch <=> other.patch if result == 0
  result
end

#==(other) ⇒ Object



20
21
22
# File 'lib/ronan/semantic_version.rb', line 20

def ==(other)
  (self <=> other) == 0
end

#to_sObject



24
25
26
# File 'lib/ronan/semantic_version.rb', line 24

def to_s
  "#{major}.#{minor}.#{patch}"
end