Class: Cassowary::EditOrStayConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- Cassowary::EditOrStayConstraint
- Defined in:
- lib/constraint/edit_or_stay_constraint.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#variable ⇒ Object
Returns the value of attribute variable.
Attributes inherited from Constraint
Instance Method Summary collapse
- #expression ⇒ Object
-
#initialize(hash = {}) ⇒ EditOrStayConstraint
constructor
A new instance of EditOrStayConstraint.
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
#variable ⇒ Object
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
#expression ⇒ Object
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 |