Class Uttk::Weights::WExpr
In: lib/uttk/weights/WExpr.rb
Parent: Weight

Methods

*   +   get   new   normalize   to_s   to_yaml  

Attributes

expr  [RW] 

Public Class methods

[Source]

# File lib/uttk/weights/WExpr.rb, line 15
      def initialize ( aFloat, min=0, max=1, expr=nil )
        super(aFloat, min, max)
        @expr = expr || "#{to_f}[#@min, #@max]"
      end

Public Instance methods

[Source]

# File lib/uttk/weights/WExpr.rb, line 26
      def * ( rhs )
        x = super
        x.expr = "(#{to_s} * #{rhs.to_s})[#{x.min}, #{x.max}]"
        x
      end

[Source]

# File lib/uttk/weights/WExpr.rb, line 20
      def + ( rhs )
        x = super
        x.expr = "(#{@expr} + #{rhs.to_s})[#{x.min}, #{x.max}]"
        x
      end

[Source]

# File lib/uttk/weights/WExpr.rb, line 48
      def get
        @expr + " == #{to_f.to_s} == #{(to_f * 100).floor}%"
      end

[Source]

# File lib/uttk/weights/WExpr.rb, line 33
      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

[Source]

# File lib/uttk/weights/WExpr.rb, line 52
      def to_s
        @expr
      end

[Source]

# File lib/uttk/weights/WExpr.rb, line 56
      def to_yaml ( opts={} )
        if opts[:uttk]
          to_f.to_yaml(opts)
        else
          super
        end
      end

[Validate]