Class: Ronan::SemanticVersion
- Inherits:
-
Object
- Object
- Ronan::SemanticVersion
- Defined in:
- lib/ronan/semantic_version.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#patch ⇒ Object
Returns the value of attribute patch.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(version_str) ⇒ SemanticVersion
constructor
A new instance of SemanticVersion.
- #to_s ⇒ Object
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
#major ⇒ Object
Returns the value of attribute major.
3 4 5 |
# File 'lib/ronan/semantic_version.rb', line 3 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
3 4 5 |
# File 'lib/ronan/semantic_version.rb', line 3 def minor @minor end |
#patch ⇒ Object
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_s ⇒ Object
24 25 26 |
# File 'lib/ronan/semantic_version.rb', line 24 def to_s "#{major}.#{minor}.#{patch}" end |