Sha256: fd48cb817d4996379efebb1c3ee274a330ea95613e10449018f39d1b6c1fb811

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Fathom
  class Variable
    
    # =================
    # = Class Methods =
    # =================
    class << self
      def infer(obj)
        case obj
        when Variable
          obj
        when Hash
          new(obj)
        when Symbol, String
          new(:name => obj)
        end
      end
    end
    
    # ============
    # = Behavior =
    # ============
    extend Plugins
    plugin AttributeSystem
    
    # ==============
    # = Attributes =
    # ==============
    attribute :id
    attribute :name
    attribute :properties
    attribute :outcomes, [true, false]
    attribute :prior_odds
    
    def initialize(attrs={})
      attrs[:id] ||= UUID.generate
      @attributes = attrs
      self.prior_odds ||= uniform_set.dup
    end
    
    def underscored_name
      name.to_s.gsub(/\W/, "_").underscore
    end
    
    def eql(other)
      return false unless other.is_a?(Variable)
      self.name == other.name
    end
    alias :== :eql
    
    protected
      def uniform_set
        size = self.outcomes.size
        Array.new(size, 1/size.to_f)
      end
    
  end # class Data
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fathom-0.5.0 lib/fathom/data/variable.rb