Sha256: dca4cc12b6450b3741f061dba0ea706712fe73ddac2b611f71f9554d55a6b63a

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

# Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
# Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved.
# License::   LGPL
# $Id: /w/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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uttk-0.4.6.1 lib/uttk/weights/WExpr.rb
uttk-0.4.5.0 lib/uttk/weights/WExpr.rb
uttk-0.4.6.2 lib/uttk/weights/WExpr.rb