Class: ProportionBoundedSubtractInstruction

Inherits:
Instruction
  • Object
show all
Defined in:
lib/instructions/proportion/proportion_bounded_subtract.rb

Overview

pops the top 2 items of the :proportion stack; pushes a ValuePoint with their difference (or 0.0, whichever is bigger) onto the :proportion stack

note: the first item popped is the number to be subtracted from the other

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



22
23
24
# File 'lib/instructions/proportion/proportion_bounded_subtract.rb', line 22

def cleanup
  pushes :proportion, @result
end

#deriveObject



19
20
21
# File 'lib/instructions/proportion/proportion_bounded_subtract.rb', line 19

def derive
  @result = ValuePoint.new("proportion", [@arg1 - @arg2, 0.0].max)
end

#preconditions?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/instructions/proportion/proportion_bounded_subtract.rb', line 12

def preconditions?
  needs :proportion, 2
end

#setupObject



15
16
17
18
# File 'lib/instructions/proportion/proportion_bounded_subtract.rb', line 15

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