Class: Bringit::VersionInfo
- Inherits:
-
Object
- Object
- Bringit::VersionInfo
- Includes:
- Comparable
- Defined in:
- lib/bringit/version_info.rb
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(major = 0, minor = 0, patch = 0) ⇒ VersionInfo
constructor
A new instance of VersionInfo.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(major = 0, minor = 0, patch = 0) ⇒ VersionInfo
Returns a new instance of VersionInfo.
15 16 17 18 19 |
# File 'lib/bringit/version_info.rb', line 15 def initialize(major = 0, minor = 0, patch = 0) @major = major @minor = minor @patch = patch end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
5 6 7 |
# File 'lib/bringit/version_info.rb', line 5 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
5 6 7 |
# File 'lib/bringit/version_info.rb', line 5 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
5 6 7 |
# File 'lib/bringit/version_info.rb', line 5 def patch @patch end |
Class Method Details
.parse(str) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/bringit/version_info.rb', line 7 def self.parse(str) if str && m = str.match(/(\d+)\.(\d+)\.(\d+)/) VersionInfo.new(m[1].to_i, m[2].to_i, m[3].to_i) else VersionInfo.new end end |
Instance Method Details
#<=>(other) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bringit/version_info.rb', line 21 def <=>(other) return unless other.is_a? VersionInfo return unless valid? && other.valid? if other.major < @major 1 elsif @major < other.major -1 elsif other.minor < @minor 1 elsif @minor < other.minor -1 elsif other.patch < @patch 1 elsif @patch < other.patch -1 else 0 end end |
#to_s ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/bringit/version_info.rb', line 42 def to_s if valid? "%d.%d.%d" % [@major, @minor, @patch] else "Unknown" end end |
#valid? ⇒ Boolean
50 51 52 |
# File 'lib/bringit/version_info.rb', line 50 def valid? @major >= 0 && @minor >= 0 && @patch >= 0 && @major + @minor + @patch > 0 end |