Sha256: 2d9bba542a017f81b4540fcc7b128cc231e96cc6d54d2c4f3ee37782f6b11a7c

Contents?: true

Size: 823 Bytes

Versions: 9

Compression:

Stored size: 823 Bytes

Contents

module Zapata
  module Predictor
    class Value
      extend Memoist

      def initialize(name, finder = nil)
        @name = name
        @finder = finder
      end

      def choose
        return Primitive::Raw.new(:nil, nil) if @name.nil?
        return @finder if @finder and FINAL_TYPES.include?(@finder.type)
        return Primitive::Raw.new(:super, @name) if possible_values.empty?
        Chooser.new(possible_values).by_probability
      end

      def a_finder?(primitive)
        return false unless @finder
        primitive.class == @finder.class and primitive.name == @finder.name
      end

      def possible_values
        Revolutionist.analysis_as_array.select do |element|
          !a_finder?(element) and element.name == @name
        end
      end
      memoize :possible_values
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
zapata-0.1.6 lib/zapata/predictor/value.rb
zapata-0.1.5 lib/zapata/predictor/value.rb
zapata-0.1.4 lib/zapata/predictor/value.rb
zapata-0.1.3 lib/zapata/predictor/value.rb
zapata-0.1.2 lib/zapata/predictor/value.rb
zapata-0.1.1 lib/zapata/predictor/value.rb
zapata-0.1.0 lib/zapata/predictor/value.rb
zapata-0.0.3 lib/zapata/predictor/value.rb
zapata-0.0.2 lib/zapata/predictor/value.rb