Class: ProportionBoundedAddInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/proportion/proportion_bounded_add.rb

Overview

pops the top 2 items of the :proportion stack; pushes a ValuePoint with their sum (or 1.0, whichever is smaller) onto the :proportion stack

needs: 2 :proportion

pushes: 1 :proportion

Instance Attribute Summary

Attributes inherited from Instruction

#context

Instance Method Summary collapse

Methods inherited from Instruction

all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode

Constructor Details

This class inherits a constructor from Instruction

Instance Method Details

#cleanupObject



20
21
22
# File 'lib/instructions/proportion/proportion_bounded_add.rb', line 20

def cleanup
  pushes :proportion, @result
end

#deriveObject



17
18
19
# File 'lib/instructions/proportion/proportion_bounded_add.rb', line 17

def derive
  @result = ValuePoint.new("proportion", [@arg1 + @arg2, 1.0].min)
end

#preconditions?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/instructions/proportion/proportion_bounded_add.rb', line 10

def preconditions?
  needs :proportion, 2
end

#setupObject



13
14
15
16
# File 'lib/instructions/proportion/proportion_bounded_add.rb', line 13

def setup
  @arg1 = @context.pop_value(:proportion)
  @arg2 = @context.pop_value(:proportion)
end