Class: RSpec::Support::ComparableVersion Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Comparable
|
|
Inherits: | Object |
Defined in: | rspec-support/lib/rspec/support/comparable_version.rb |
Class Method Summary
- .new(string) ⇒ ComparableVersion constructor Internal use only
Instance Attribute Summary
- #string readonly Internal use only
Instance Method Summary
- #<=>(other) Internal use only
- #segments Internal use only
Instance Attribute Details
#string (readonly)
[ GitHub ]# File 'rspec-support/lib/rspec/support/comparable_version.rb', line 9
attr_reader :string
Instance Method Details
#<=>(other)
[ GitHub ]# File 'rspec-support/lib/rspec/support/comparable_version.rb', line 15
def <=>(other) other = self.class.new(other) unless other.is_a?(self.class) return 0 if string == other.string longer_segment_count = [self, other].map { |version| version.segments.count }.max longer_segment_count.times do |index| self_segment = segments[index] || 0 other_segment = other.segments[index] || 0 if self_segment.class == other_segment.class result = self_segment <=> other_segment return result unless result == 0 else return self_segment.is_a?(String) ? -1 : 1 end end 0 end
#segments
[ GitHub ]# File 'rspec-support/lib/rspec/support/comparable_version.rb', line 37
def segments @segments ||= string.scan(/[a-z]+|\d+/i).map do |segment| if segment =~ /\A\d+\z/ segment.to_i else segment end end end