Sha256: 2860f4c12cc2cbfbf61765d7fc8c1f4b911f3ac8bbe847ab83dfcfcdb61830df

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module Ore
  #
  # Represents a RubyGem dependency.
  #
  class Dependency

    # The name of the dependency
    attr_reader :name

    # The required versions
    attr_reader :versions

    #
    # Creates a new dependency.
    #
    # @param [String] name
    #   The name of the dependency.
    #
    # @param [Array<String>] versions
    #   The required versions.
    #
    def initialize(name,*versions)
      @name = name
      @versions = versions
    end

    #
    # Parses a version string.
    #
    # @param [String] name
    #   The name of the dependency.
    #
    # @param [String, Array, nil] versions 
    #   The version(s).
    #
    # @return [Dependency]
    #   The parsed dependency.
    #
    def self.parse_versions(name,versions)
      versions = case versions
                 when String
                   versions.strip.split(/,\s*/)
                 when Array
                   versions.map { |v| v.to_s }
                 else
                   []
                 end

      return new(name,*versions)
    end

    #
    # Parses a dependencey string.
    #
    # @param [String] dependency
    #   The dependencey string.
    #
    # @return [Dependency]
    #   The parsed dependency.
    #
    def self.parse(dependency)
      name, versions = dependency.strip.split(/\s+/,2)

      return parse_versions(name,versions)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ore-core-0.1.1 lib/ore/dependency.rb