Class: SQLCodeAI
Instance Attribute Summary
Attributes inherited from BaseCodeAI
#questions
Instance Method Summary
collapse
Methods inherited from BaseCodeAI
#clone_array, #filename, #lines, #lines_to_html, #lines_to_s, #make_questions, #name, #num, #process?, #type
Constructor Details
#initialize(code) ⇒ SQLCodeAI
7
8
9
10
|
# File 'lib/asker/ai/code/sql_code_ai.rb', line 7
def initialize(code)
@lang = LangFactory.instance.get('sql')
super code
end
|
Instance Method Details
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
|
# File 'lib/asker/ai/code/sql_code_ai.rb', line 12
def
error_lines = []
questions = []
@lines.each_with_index do |line,index|
if line.include?('//')
lines = clone_array @lines
lines[index].sub!('//','').strip!
q = Question.new(:short)
q.name = "#{name}-#{num}-code1uncomment"
q.text = @lang.text_for(:code1,lines_to_html(lines))
q.shorts << (index+1)
q.feedback = 'Comment symbol removed'
questions << q
elsif line.strip.size>0
lines = clone_array @lines
lines[index]='// ' + lines[index]
q = Question.new(:short)
q.name = "#{name}-#{num}-code1comment"
q.text = @lang.text_for(:code1,lines_to_html(lines))
q.shorts << (index+1)
q.feedback = 'Comment symbol added'
questions << q
end
end
questions
end
|
#make_keyword_error ⇒ Object
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
|
# File 'lib/asker/ai/code/sql_code_ai.rb', line 41
def make_keyword_error
error_lines = []
questions = []
@lang.mistakes.each_pair do |key,values|
v = values.split(',')
v.each do |value|
@lines.each_with_index do |line,index|
error_lines << index if line.include?(key.to_s)
end
error_lines.each do |index|
lines = clone_array @lines
lines[index].sub!(key.to_s, value)
q = Question.new(:short)
q.name = "#{name}-#{num}-code1keyword"
q.text = @lang.text_for(:code1,lines_to_html(lines))
q.shorts << (index+1)
q.feedback = "Keyword error: '#{value}' must be '#{key}'"
questions << q
end
end
end
questions
end
|