Class: Shaf::Upgrade::Version
- Inherits:
-
Object
- Object
- Shaf::Upgrade::Version
- Includes:
- Comparable
- Defined in:
- lib/shaf/upgrade/version.rb
Defined Under Namespace
Classes: UpgradeVersionError
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.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/shaf/upgrade/version.rb', line 16 def initialize(version) case version when Version @major, @minor, @patch = version.to_a when /\d+\.\d+(\.\d+)?/ @major, @minor, @patch = split_version(version) else raise UpgradeVersionError, version end end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
6 7 8 |
# File 'lib/shaf/upgrade/version.rb', line 6 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
6 7 8 |
# File 'lib/shaf/upgrade/version.rb', line 6 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
6 7 8 |
# File 'lib/shaf/upgrade/version.rb', line 6 def patch @patch end |
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 30 31 |
# File 'lib/shaf/upgrade/version.rb', line 27 def <=>(other) return unless other other = self.class.new(other) compare_version(other.major, other.minor, other.patch) end |
#to_a ⇒ Object
37 38 39 |
# File 'lib/shaf/upgrade/version.rb', line 37 def to_a [major, minor, patch] end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/shaf/upgrade/version.rb', line 33 def to_s to_a.join('.') end |