# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved. # License:: LGPL # $Id: /fey/uttk/trunk/lib/uttk/weights/WExpr.rb 8778 2005-09-26T04:34:48.103938Z ertai $ module Uttk module Weights class WExpr < Weight attr_accessor :expr def initialize ( aFloat, min=0, max=1, expr=nil ) super(aFloat, min, max) @expr = expr || "#{to_f}[#@min, #@max]" end def + ( rhs ) x = super x.expr = "(#{@expr} + #{rhs.to_s})[#{x.min}, #{x.max}]" x end def * ( rhs ) x = super x.expr = "(#{to_s} * #{rhs.to_s})[#{x.min}, #{x.max}]" x end def normalize ( weight ) diff = @max - @min if diff.zero? if @max.zero? and weight.zero? self.class.new(:PASS) else self.class.new(:FAIL) end else self.class.new((self - @min) / diff, 0, 1, "((#{to_s} - #{min.to_s}) / (#{max.to_s} - #{min.to_s}))") end end def get @expr + " == #{to_f.to_s} == #{(to_f * 100).floor}%" end def to_s @expr end def to_yaml ( opts={} ) if opts[:uttk] to_f.to_yaml(opts) else super end end end # class WExpr end # module Weights end # module Uttk