Class: StageB
Instance Method Summary collapse
- #process_table_match2fields(pTable, pList1, pList2, pIndex1, pIndex2) ⇒ Object
-
#run(pTable, pList1, pList2) ⇒ Object
range b1.
Methods inherited from BaseStage
Constructor Details
This class inherits a constructor from BaseStage
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BaseStage
Instance Method Details
#process_table_match2fields(pTable, pList1, pList2, pIndex1, pIndex2) ⇒ Object
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 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 |
# File 'lib/asker/ai/stages/stage_b.rb', line 32 def process_table_match2fields(pTable, pList1, pList2, pIndex1, pIndex2) questions = [] if pList1.count>3 pList1.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.to_s}-b1match4x4-#{pTable.name}" q.text= random_image_for(name) + lang.text_for(:b1, name, pTable.fields[pIndex1].capitalize, pTable.fields[pIndex2].capitalize ) q.matching << [ e[0][:data][pIndex1], e[0][:data][pIndex2] ] q.matching << [ e[1][:data][pIndex1], e[1][:data][pIndex2] ] q.matching << [ e[2][:data][pIndex1], e[2][:data][pIndex2] ] q.matching << [ e[3][:data][pIndex1], e[3][:data][pIndex2] ] 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.to_s}-b1match3x1misspelled-#{pTable.name}" q.text= random_image_for(name) + lang.text_for(:b1, name, pTable.fields[pIndex1].capitalize, pTable.fields[pIndex2].capitalize ) q.matching << [ e[0][:data][pIndex1], e[0][:data][pIndex2] ] q.matching << [ e[1][:data][pIndex1], e[1][:data][pIndex2] ] q.matching << [ e[2][:data][pIndex1], e[2][:data][pIndex2] ] q.matching << [ lang.do_mistake_to(e[3][:data][pIndex1]), lang.text_for(:misspelling) ] questions << q end end if pList1.count>2 and pList2.count>0 s=Set.new pList1.each do |i| s.add( i[:data][pIndex1]+"<=>"+i[:data][pIndex2] ) end s.add( pList2[0][:data][pIndex1]+"<=>"+pList2[0][:data][pIndex2] ) a=s.to_a # Question 3 items from table-A, and 1 item from table-B if s.count > 3 q=Question.new(:match) q.name="#{name}-#{num.to_s}-b1match3x1-#{pTable.name}" q.text= random_image_for(name) + lang.text_for(:b1, name , pTable.fields[pIndex1].capitalize, pTable.fields[pIndex2].capitalize) q.matching << [ pList1[0][:data][pIndex1], pList1[0][:data][pIndex2] ] q.matching << [ pList1[1][:data][pIndex1], pList1[1][:data][pIndex2] ] q.matching << [ pList1[2][:data][pIndex1], pList1[2][:data][pIndex2] ] q.matching << [ pList2[0][:data][pIndex1], lang.text_for(:error) ] questions << q end end return questions end |
#run(pTable, pList1, pList2) ⇒ Object
range b1
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/asker/ai/stages/stage_b.rb', line 11 def run(pTable, pList1, pList2) # process table match questions = [] return questions if pTable.fields.count < 2 return questions unless type == 'text' if pTable.fields.count>1 then questions += process_table_match2fields(pTable, pList1, pList2, 0, 1) elsif pTable.fields.count>2 then questions += process_table_match2fields(pTable, pList1, pList2, 0, 2) questions += process_table_match2fields(pTable, pList1, pList2, 1, 2) elsif pTable.fields.count>3 then questions += process_table_match2fields(pTable, pList1, pList2, 0, 3) questions += process_table_match2fields(pTable, pList1, pList2, 1, 3) questions += process_table_match2fields(pTable, pList1, pList2, 2, 3) end questions end |