Class: ConceptAI

Inherits:
Object
  • Object
show all
Includes:
AI
Defined in:
lib/asker/ai/concept_ai.rb

Overview

ConceptAI: Add more info to every Concept instance.

Encapsulating AI data => questions
  • concept

  • questions

  • num

  • random_image_for

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AI

#exclude_questions, #make_questions, #make_questions_stages_bsf, #make_questions_stages_di, #make_questions_stages_t, #string_has_this_tags?

Methods included from AI_calculate

#calculate_nearness_between_texts, #get_list1_and_list2_from, #reorder_list_with_row

Constructor Details

#initialize(concept, world) ⇒ ConceptAI

Returns a new instance of ConceptAI.



20
21
22
23
24
25
26
# File 'lib/asker/ai/concept_ai.rb', line 20

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 # Used to add a unique number to every question
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

If a method call is missing, then delegate to concept parent.



34
35
36
# File 'lib/asker/ai/concept_ai.rb', line 34

def method_missing(method, *args, &block)
  @concept.send(method, *args, &block)
end

Instance Attribute Details

#conceptObject (readonly)

Returns the value of attribute concept.



16
17
18
# File 'lib/asker/ai/concept_ai.rb', line 16

def concept
  @concept
end

#excluded_questionsObject (readonly)

Returns the value of attribute excluded_questions.



18
19
20
# File 'lib/asker/ai/concept_ai.rb', line 18

def excluded_questions
  @excluded_questions
end

#questionsObject (readonly)

Returns the value of attribute questions.



17
18
19
# File 'lib/asker/ai/concept_ai.rb', line 17

def questions
  @questions
end

Instance Method Details

#numObject



28
29
30
31
# File 'lib/asker/ai/concept_ai.rb', line 28

def num
  @num += 1
  @num.to_s
end

#random_image_for(_conceptname) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/asker/ai/concept_ai.rb', line 38

def random_image_for(_conceptname)
  return '' if rand <= Project.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