Class: Chewy::Runtime::Version
- Inherits:
-
Object
- Object
- Chewy::Runtime::Version
- Includes:
- Comparable
- Defined in:
- lib/chewy/runtime/version.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.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
Returns a new instance of Version.
7 8 9 |
# File 'lib/chewy/runtime/version.rb', line 7 def initialize(version) @major, @minor, @patch = *(version.to_s.split('.', 3) + ([0] * 3)).first(3).map(&:to_i) end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
5 6 7 |
# File 'lib/chewy/runtime/version.rb', line 5 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
5 6 7 |
# File 'lib/chewy/runtime/version.rb', line 5 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
5 6 7 |
# File 'lib/chewy/runtime/version.rb', line 5 def patch @patch end |
Instance Method Details
#<=>(other) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/chewy/runtime/version.rb', line 15 def <=>(other) other = self.class.new(other) unless other.is_a?(self.class) [ major <=> other.major, minor <=> other.minor, patch <=> other.patch ].detect(&:nonzero?) || 0 end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/chewy/runtime/version.rb', line 11 def to_s [major, minor, patch].join('.') end |