Class: Cassowary::EditOrStayConstraint

Inherits:
Constraint show all
Defined in:
lib/constraint/edit_or_stay_constraint.rb

Direct Known Subclasses

EditConstraint, StayConstraint

Instance Attribute Summary collapse

Attributes inherited from Constraint

#strength, #weight

Instance Method Summary collapse

Methods inherited from Constraint

#edit_constraint?, #inequality?, #required?, #stay_constraint?

Constructor Details

#initialize(hash = {}) ⇒ EditOrStayConstraint

Returns a new instance of EditOrStayConstraint.



7
8
9
10
11
12
# File 'lib/constraint/edit_or_stay_constraint.rb', line 7

def initialize(hash = {})
  hash = {:weight => 1.0}.merge(hash)
  self.variable = hash[:variable]
  self.strength = hash[:strength]
  self.weight = hash[:weight]
end

Instance Attribute Details

#variableObject

Returns the value of attribute variable.



5
6
7
# File 'lib/constraint/edit_or_stay_constraint.rb', line 5

def variable
  @variable
end

Instance Method Details

#expressionObject



14
15
16
17
18
19
# File 'lib/constraint/edit_or_stay_constraint.rb', line 14

def expression
  e = LinearExpression.new
  e.constant = variable.value
  e.terms[variable] = -1.0
  e
end