Class: Solve::Demand

Inherits:
Object
  • Object
show all
Defined in:
lib/solve/demand.rb

Overview

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(solver, name, constraint = ">= 0.0.0") ⇒ Demand

Returns a new instance of Demand.

Parameters:



22
23
24
25
26
27
28
29
30
# File 'lib/solve/demand.rb', line 22

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

Instance Attribute Details

#constraintSolve::Constraint (readonly)

The acceptable constraint of the artifact this demand is for

Returns:



17
18
19
# File 'lib/solve/demand.rb', line 17

def constraint
  @constraint
end

#nameString (readonly)

The name of the artifact this demand is for

Returns:

  • (String)


12
13
14
# File 'lib/solve/demand.rb', line 12

def name
  @name
end

#solverSolve::Solver (readonly)

A reference to the solver this demand belongs to

Returns:



7
8
9
# File 'lib/solve/demand.rb', line 7

def solver
  @solver
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



47
48
49
50
51
# File 'lib/solve/demand.rb', line 47

def ==(other)
  other.is_a?(self.class) &&
    self.name == other.name &&
    self.constraint == other.constraint
end

#deleteSolve::Demand?

Remove this demand from the solver it belongs to

Returns:



35
36
37
38
39
40
41
# File 'lib/solve/demand.rb', line 35

def delete
  unless solver.nil?
    result = solver.remove_demand(self)
    @solver = nil
    result
  end
end

#to_sObject



43
44
45
# File 'lib/solve/demand.rb', line 43

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