Sha256: ff143c42bb7959eb8936672b4ff3c0180f0abcfad3fc76a69a8837a8e79b066c

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require_relative "../lang/lang"
require_relative "ai"
require_relative "question"

# Add more info to every Concept instance.
# Encapsulating AI data => questions
class ConceptAI
  include AI

  attr_reader :concept
  attr_reader :questions
  attr_reader :excluded_questions

  def initialize(concept, world)
    @concept = concept
    @world = world
    @questions = {d: [], b: [], f: [], i: [], s: [], t: []}
    @excluded_questions = {d: [], b: [], f: [], i: [], s: [], t: []}
    @num = 0 # Add a unique number to every question
    make_questions
  end

  def num
    # Generates and return new "num" value
    @num += 1
    @num.to_s
  end

  # If a method call is missing, then delegate to concept parent.
  def method_missing(method, *args, &block)
    raise "[DEBUG] ConceptAI.#{method}(#{args})"
    @concept.send(method, *args, &block)
  end

  def random_image_for(_conceptname)
    # Generates random image URL
    return "" if rand <= ProjectData.instance.get(:threshold)

    keys = @world.image_urls.keys
    keys.shuffle!
    values = @world.image_urls[keys[0]] # keys[0] could be conceptname
    return "" if values.nil?

    values.shuffle!
    "<img src=\"#{values[0]}\" alt=\"image\"><br/>"
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
asker-tool-2.9.4 lib/asker/ai/concept_ai.rb
asker-tool-2.9.3 lib/asker/ai/concept_ai.rb
asker-tool-2.9.2 lib/asker/ai/concept_ai.rb
asker-tool-2.9.1 lib/asker/ai/concept_ai.rb
asker-tool-2.9.0 lib/asker/ai/concept_ai.rb
asker-tool-2.8.0 lib/asker/ai/concept_ai.rb
asker-tool-2.7.2 lib/asker/ai/concept_ai.rb
asker-tool-2.7.1 lib/asker/ai/concept_ai.rb
asker-tool-2.7.0 lib/asker/ai/concept_ai.rb