Class: Avm::VersionNumber
- Inherits:
-
Object
- Object
- Avm::VersionNumber
- Includes:
- Comparable
- Defined in:
- lib/avm/version_number.rb
Overview
A sequence of segments of integer versions (Ex.: 2, 1.0.1, 3.0.0.0.0).
Constant Summary collapse
- SEGMENT_SEPARATOR =
'.'
Instance Attribute Summary collapse
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #increment_segment(segment_index) ⇒ Avm::Version
-
#initialize(segments) ⇒ VersionNumber
constructor
A new instance of VersionNumber.
- #to_s ⇒ Object
Constructor Details
#initialize(segments) ⇒ VersionNumber
Returns a new instance of VersionNumber.
19 20 21 |
# File 'lib/avm/version_number.rb', line 19 def initialize(segments) @segments = self.class.segments_from_mixed(segments).freeze end |
Instance Attribute Details
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
17 18 19 |
# File 'lib/avm/version_number.rb', line 17 def segments @segments end |
Class Method Details
.segments_from_mixed(segments) ⇒ Object
11 12 13 14 |
# File 'lib/avm/version_number.rb', line 11 def segments_from_mixed(segments) (segments.is_a?(::Enumerable) ? segments.to_a : segments.to_s.split(SEGMENT_SEPARATOR)) .map(&:to_i) end |
Instance Method Details
#<=>(other) ⇒ Object
25 26 27 |
# File 'lib/avm/version_number.rb', line 25 def <=>(other) segments <=> other.segments end |
#increment_segment(segment_index) ⇒ Avm::Version
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/avm/version_number.rb', line 34 def increment_segment(segment_index) x = [segments.count, segment_index + 1].max.times.map do |index| value = index < segments.count ? segments[index] : 0 next value if index < segment_index next value + 1 if index == segment_index 0 end self.class.new x end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/avm/version_number.rb', line 29 def to_s segments.join(SEGMENT_SEPARATOR) end |