Class: StageS

Inherits:
BaseStage show all
Defined in:
lib/asker/ai/stages/stage_s.rb

Instance Method Summary collapse

Methods inherited from BaseStage

#concept, #images, #initialize, #lang, #name, #names, #neighbors, #num, #random_image_for, #texts, #type

Constructor Details

This class inherits a constructor from BaseStage

Instance Method Details

#run(table, list1, _list2) ⇒ Object

process_sequence



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/asker/ai/stages/stage_s.rb', line 8

def run(table, list1, _list2)
  questions = []
  return questions unless table.fields.count == 1 && table.sequence? && table.sequence[0] != ""

  lang = concept.lang
  # Question: items are part of a sequence
  if list1.count > 3
    a = 0..(list1.count - 4)
    a.each_entry do |i|
      q = Question.new(:match)
      q.name = "#{name}-#{num}-s1sequence-#{table.name}"
      q.text = random_image_for(name) + lang.text_for(:s1, name, table.fields[0].capitalize, table.sequence[0])
      q.matching << [list1[i + 0][:data][0], ""]
      q.matching << [list1[i + 1][:data][0], ""]
      q.matching << [list1[i + 2][:data][0], ""]
      q.matching << [list1[i + 3][:data][0], ""]
      q.matching << ["", lang.text_for(:error)]
      questions << q
    end

    q = Question.new(:ordering)
    q.name = "#{name}-#{num}-s1sequence-#{table.name}"
    q.text = random_image_for(name) + lang.text_for(:s1, name, table.fields[0].capitalize, table.sequence[0])
    list1.each { |item| q.ordering << item[:data][0] }
    questions << q
  end

  # Question: items are part of a reverse sequence
  if list1.count > 3 && table.sequence.size > 1
    a = 0..(list1.count - 4)
    a.each_entry do |i|
      q = Question.new(:match)
      q.name = "#{name}-#{num}-s2sequence-#{table.name}"
      q.text = random_image_for(name) + lang.text_for(:s1, name, table.fields[0].capitalize, table.sequence[1])
      q.matching << [list1[i + 3][:data][0], ""]
      q.matching << [list1[i + 2][:data][0], ""]
      q.matching << [list1[i + 1][:data][0], ""]
      q.matching << [list1[i + 0][:data][0], ""]
      q.matching << ["", lang.text_for(:error)]
      questions << q
    end

    q = Question.new(:ordering)
    q.name = "#{name}-#{num}-s2sequence-#{table.name}"
    q.text = random_image_for(name) + lang.text_for(:s1, name, table.fields[0].capitalize, table.sequence[1])
    list1.reverse.to_a.each { |item| q.ordering << item[:data][0] }
    questions << q
  end

  questions
end