Class: BaseCodeAI

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/ai/code/base_code_ai.rb

Overview

BaseCodeAI class

Direct Known Subclasses

JavascriptCodeAI, PythonCodeAI, RubyCodeAI, SQLCodeAI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ BaseCodeAI

Returns a new instance of BaseCodeAI.



11
12
13
14
15
16
17
# File 'lib/asker/ai/code/base_code_ai.rb', line 11

def initialize(code)
  @code = code
  @lines = code.lines
  @num = 0
  @questions = []
  make_questions
end

Instance Attribute Details

#questionsObject (readonly)

Returns the value of attribute questions.



9
10
11
# File 'lib/asker/ai/code/base_code_ai.rb', line 9

def questions
  @questions
end

Instance Method Details

#clone_array(array) ⇒ Object



43
44
45
46
47
# File 'lib/asker/ai/code/base_code_ai.rb', line 43

def clone_array(array)
  out = []
  array.each { |item| out << item.dup }
  out
end

#filenameObject



31
32
33
# File 'lib/asker/ai/code/base_code_ai.rb', line 31

def filename
  @code.filename
end

#linesObject



35
36
37
# File 'lib/asker/ai/code/base_code_ai.rb', line 35

def lines
  @code.lines
end

#lines_to_html(lines) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/asker/ai/code/base_code_ai.rb', line 57

def lines_to_html(lines)
  out = ""
  lines.each_with_index do |line, index|
    out << "%2d: #{line}</br>" % (index + 1)
  end
  out
end

#lines_to_s(lines) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/asker/ai/code/base_code_ai.rb', line 49

def lines_to_s(lines)
  out = ""
  lines.each_with_index do |line, index|
    out << "%2d: #{line}\n" % (index + 1)
  end
  out
end

#make_questionsObject



65
66
67
68
69
# File 'lib/asker/ai/code/base_code_ai.rb', line 65

def make_questions
  list = find_make_methods
  list.each { |m| @questions += send m }
  @questions
end

#nameObject



19
20
21
# File 'lib/asker/ai/code/base_code_ai.rb', line 19

def name
  File.basename(@code.filename)
end

#numObject



39
40
41
# File 'lib/asker/ai/code/base_code_ai.rb', line 39

def num
  @num += 1
end

#process?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/asker/ai/code/base_code_ai.rb', line 23

def process?
  @code.process?
end

#typeObject



27
28
29
# File 'lib/asker/ai/code/base_code_ai.rb', line 27

def type
  @code.type
end