Sha256: ef667f718187f6e2d401729b2887386e55579ec5a9f40c8f1db687658c68a2bb

Contents?: true

Size: 1.07 KB

Versions: 1553

Compression:

Stored size: 1.07 KB

Contents

module RSpec
  module Support
    # @private
    class ComparableVersion
      include Comparable

      attr_reader :string

      def initialize(string)
        @string = string
      end

      def <=>(other) # rubocop:disable Metrics/AbcSize
        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

      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
    end
  end
end

Version data entries

1,553 entries across 1,541 versions & 28 rubygems

Version Path
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
ory-kratos-client-0.7.6.alpha3 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
ory-kratos-client-0.7.6.alpha1 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
ory-kratos-client-0.7.5.alpha2 vendor/bundle/ruby/2.5.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
mx-platform-ruby-0.4.0 vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
mx-platform-ruby-0.3.2 vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
mx-platform-ruby-0.3.1 vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/rspec-support-3.10.0/lib/rspec/support/comparable_version.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/rspec-support-3.10.2/lib/rspec/support/comparable_version.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/rspec-support-3.10.0/lib/rspec/support/comparable_version.rb