Sha256: ef609c15a1cd563cad5e57a6a089365ffc37d561e82caf7d9d89f93550bc4460

Contents?: true

Size: 564 Bytes

Versions: 1

Compression:

Stored size: 564 Bytes

Contents

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

class ProportionBoundedAddInstruction < Instruction
  def preconditions?
    needs :proportion, 2
  end
  def setup
    @arg1 = @context.pop_value(:proportion)
    @arg2 = @context.pop_value(:proportion)
  end
  def derive
    @result = ValuePoint.new("proportion", [@arg1 + @arg2, 1.0].min)
  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_add.rb