Sha256: a72d11ee9ff36de67a5c71520301e02d088de34ab3d6d42ee7d3a393c2db1fa0

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Solve
  # @author Jamie Winsor <jamie@vialstudios.com>
  class Demand
    # A reference to the solver this demand belongs to
    #
    # @return [Solve::Solver]
    attr_reader :solver

    # The name of the artifact this demand is for
    #
    # @return [String]
    attr_reader :name

    # The acceptable constraint of the artifact this demand is for
    #
    # @return [Solve::Constraint]
    attr_reader :constraint

    # @param [Solve::Solver] solver
    # @param [#to_s] name
    # @param [Solve::Constraint, #to_s] constraint
    def initialize(solver, name, constraint = ">= 0.0.0")
      @solver = solver
      @name = name
      @constraint = if constraint.is_a?(Solve::Constraint)
        constraint
      else
        Constraint.new(constraint.to_s)
      end
    end

    # Remove this demand from the solver it belongs to
    #
    # @return [Solve::Demand, nil]
    def delete
      unless solver.nil?
        result = solver.remove_demand(self)
        @solver = nil
        result
      end
    end

    def to_s
      "#{name} (#{constraint})"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solve-0.3.0 lib/solve/demand.rb