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

FIXME: document me

Methods

*   +   ==   fail?   long_get   max?   method_missing   min?   new   normalize   pass?   start?  

Constants

BASE = { :START => [0, 0, 0], :PASS => [1, 0, 1], :FAIL => [0, 0, 1]

External Aliases

val -> get

Attributes

max  [R] 
min  [R] 
val  [R] 

Public Class methods

[Source]

# File lib/uttk/weights/Weight.rb, line 19
      def initialize ( aFloat, min=0, max=1 )
        if BASE.has_key? aFloat
          aFloat, min, max = BASE[aFloat]
        end
        aFloat = aFloat.to_f
        @val = aFloat
        @min, @max = min, max
        unless @min <= aFloat or aFloat <= @max
          raise ArgumentError, "#@min <= #{aFloat} <= #@max"
        end
      end

Public Instance methods

[Source]

# File lib/uttk/weights/Weight.rb, line 63
      def * ( rhs )
        f = rhs.to_f
        a, b, c = to_f * f, @min * f, @max * f
        b, c = c, b if f < 0
        self.class.new(a, b, c)
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 58
      def + ( rhs )
        rhs = self.class.new(rhs) unless rhs.is_a? Weight
        self.class.new(to_f + rhs.to_f, @min + rhs.min, @max + rhs.max)
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 90
      def == ( rhs )
        rhs.class <= Weight and
        @min == rhs.min and
        @val == rhs.val and
        @max == rhs.max
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 54
      def fail?
        to_f != @max
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 86
      def long_get
        "#{get}[#@min, #@max]"
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 46
      def max?
        to_f == @max
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 97
      def method_missing ( *a, &b )
        @val.send(*a, &b)
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 42
      def min?
        to_f == @min
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 70
      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)
        end
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 50
      def pass?
        ! zero? and max?
      end

[Source]

# File lib/uttk/weights/Weight.rb, line 38
      def start?
        [self, @max, @min].all? { |x| x.zero? }
      end

[Validate]