Class: StageS

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

Overview

process_sequence

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 rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity



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
# File 'lib/asker/ai/stages/stage_s.rb', line 13

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

  lang = concept.lang
  # Question type <d3sequence>: 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
  end

  # Question type <d4sequence>: 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
      q.set_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
  end

  questions
end