Class: SQLCodeAI
- Inherits:
-
BaseCodeAI
- Object
- BaseCodeAI
- SQLCodeAI
- Defined in:
- lib/asker/ai/code/sql_code_ai.rb
Instance Attribute Summary
Attributes inherited from BaseCodeAI
Instance Method Summary collapse
-
#initialize(code) ⇒ SQLCodeAI
constructor
A new instance of SQLCodeAI.
- #make_comment_error ⇒ Object
- #make_keyword_error ⇒ Object
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
Returns a new instance of 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
#make_comment_error ⇒ Object
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 make_comment_error 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 |