Sha256: 3f84d1bde894caa6eb42882b0bd40bc420bbf9d53794bdedd99d80a346c6a873

Contents?: true

Size: 1.48 KB

Versions: 12

Compression:

Stored size: 1.48 KB

Contents

# -*- coding: utf-8 -*-
module Gemirro
  ##
  # The Gem class contains data about a Gem such as the name, requirement as
  # well as providing some methods to more easily extract the specific version
  # number.
  #
  # @!attribute [r] name
  #  @return [String]
  # @!attribute [r] number
  #  @return [Integer]
  # @!attribute [r] platform
  #  @return [String]
  #
  class GemVersion
    include Comparable
    attr_reader :name, :number, :platform

    ##
    # @param [String] name
    # @param [String] number
    # @param [String] platform
    #
    def initialize(name, number, platform)
      @name     = name
      @number   = number
      @platform = platform
    end

    ##
    # Is for ruby
    #
    # @return [Boolean]
    #
    def ruby?
      !(@platform =~ /^ruby$/i).nil?
    end

    ##
    # Retrieve gem version
    #
    # @return [Gem::Version]
    #
    def version
      ::Gem::Version.create(number)
    end

    ##
    # Compare gem to another
    #
    # @return [Integer]
    #
    def <=>(other)
      sort = other.name <=> @name
      sort = version <=> other.version if sort.zero?
      sort = (other.ruby? && !ruby?) ? 1 : -1 if sort.zero? &&
                                                 ruby? != other.ruby?
      sort = other.platform <=> @platform if sort.zero?

      sort
    end

    ##
    # Gemfile name
    #
    # @return [String]
    #
    def gemfile_name
      platform = ruby? ? nil : @platform
      [@name, @number, platform].compact.join('-')
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gemirro-0.11.0 lib/gemirro/gem_version.rb
gemirro-0.10.5 lib/gemirro/gem_version.rb
gemirro-0.10.4 lib/gemirro/gem_version.rb
gemirro-0.10.3 lib/gemirro/gem_version.rb
gemirro-0.10.2 lib/gemirro/gem_version.rb
gemirro-0.10.1 lib/gemirro/gem_version.rb
gemirro-0.10.0 lib/gemirro/gem_version.rb
gemirro-0.9.1 lib/gemirro/gem_version.rb
gemirro-0.9.0 lib/gemirro/gem_version.rb
gemirro-0.8.1 lib/gemirro/gem_version.rb
gemirro-0.8.0 lib/gemirro/gem_version.rb
gemirro-0.7.0 lib/gemirro/gem_version.rb