Class: StageB
Overview
range b1
Instance Method Summary collapse
-
#process_table_match2fields(p_table, list1, list2, index1, index2) ⇒ Object
Process table data to generate match questions rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Style/ConditionalAssignment rubocop:disable Metrics/BlockLength rubocop:disable Metrics/PerceivedComplexity.
-
#run(table, list1, list2) ⇒ Object
Process table data to generate match questions rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
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
#process_table_match2fields(p_table, list1, list2, index1, index2) ⇒ Object
Process table data to generate match questions rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Style/ConditionalAssignment rubocop:disable Metrics/BlockLength rubocop:disable Metrics/PerceivedComplexity
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/asker/ai/stages/stage_b.rb', line 53 def process_table_match2fields(p_table, list1, list2, index1, index2) questions = [] lang = concept.lang if list1.count > 3 list1.each_cons(4) do |e1, e2, e3, e4| e = [e1, e2, e3, e4] # Question type <b1match>: match 4 items from the same table e.shuffle! q = Question.new(:match) q.name = "#{name}-#{num}-b1match4x4-#{p_table.name}" q. << 'match' q. << 'random' q.text = random_image_for(name) \ + lang.text_for(:b1, name, p_table.fields[index1].capitalize, p_table.fields[index2].capitalize) q.matching << [e[0][:data][index1], e[0][:data][index2]] q.matching << [e[1][:data][index1], e[1][:data][index2]] q.matching << [e[2][:data][index1], e[2][:data][index2]] q.matching << [e[3][:data][index1], e[3][:data][index2]] # Add an extra line if list2.count.positive? q.matching << ['', list2[0][:data][index2]] else q. << 'misspell' q.matching << ['', lang.do_mistake_to(e[0][:data][index2])] end questions << q # Question type <b1match>: match 3 items from table-A and 1 item with error e.shuffle! q = Question.new(:match) q.name = "#{name}-#{num}-b1match3x1misspelled-#{p_table.name}" q. << 'match' q. << 'random' q.text = random_image_for(name) \ + lang.text_for(:b1, name, p_table.fields[index1].capitalize, p_table.fields[index2].capitalize) q.matching << [e[0][:data][index1], e[0][:data][index2]] q.matching << [e[1][:data][index1], e[1][:data][index2]] q.matching << [e[2][:data][index1], e[2][:data][index2]] q.matching << [lang.do_mistake_to(e[3][:data][index1]), lang.text_for(:misspelling)] # Add an extra line if list2.count.positive? q.matching << ['', list2[0][:data][index2]] else q. << 'misspell' q.matching << ['', lang.do_mistake_to(e[0][:data][index2])] end questions << q end end if list1.count > 2 && list2.count.positive? s = Set.new list1.each do |i| s.add(i[:data][index1] + '<=>' + i[:data][index2]) end s.add(list2[0][:data][index1] + '<=>' + list2[0][:data][index2]) # Question 3 items from table-A, and 1 item from table-B if s.count > 3 q = Question.new(:match) q.name = "#{name}-#{num}-b1match3x1-#{p_table.name}" q. << 'match' q. << 'random' q.text = random_image_for(name) \ + lang.text_for(:b1, name, p_table.fields[index1].capitalize, p_table.fields[index2].capitalize) q.matching << [list1[0][:data][index1], list1[0][:data][index2]] q.matching << [list1[1][:data][index1], list1[1][:data][index2]] q.matching << [list1[2][:data][index1], list1[2][:data][index2]] q.matching << [list2[0][:data][index1], lang.text_for(:error)] q.matching << ['', lang.do_mistake_to(list1[0][:data][index2])] questions << q end end questions end |
#run(table, list1, list2) ⇒ Object
Process table data to generate match questions rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/asker/ai/stages/stage_b.rb', line 18 def run(table, list1, list2) questions = [] return questions if table.fields.count < 2 return questions unless concept.type == 'text' if table.fields.count == 2 questions += process_table_match2fields(table, list1, list2, 0, 1) elsif table.fields.count == 3 questions += process_table_match2fields(table, list1, list2, 0, 1) questions += process_table_match2fields(table, list1, list2, 0, 2) elsif table.fields.count == 4 questions += process_table_match2fields(table, list1, list2, 0, 1) questions += process_table_match2fields(table, list1, list2, 0, 2) questions += process_table_match2fields(table, list1, list2, 0, 3) end questions end |