Sha256: 56e90f47ef61b9c67f28ae5608042214c6b1036130e1c440ea15c17020ff7511

Contents?: true

Size: 655 Bytes

Versions: 1

Compression:

Stored size: 655 Bytes

Contents

# 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+
#

class ProportionBoundedSubtractInstruction < Instruction
  def preconditions?
    needs :proportion, 2
  end
  def setup
    @arg2 = @context.pop_value(:proportion)
    @arg1 = @context.pop_value(:proportion)
  end
  def derive
    @result = ValuePoint.new("proportion", [@arg1 - @arg2, 0.0].max)
  end
  def cleanup
    pushes :proportion, @result
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nudge-0.2.9 lib/instructions/proportion/proportion_bounded_subtract.rb