Class: Customizer

Inherits:
Object
  • Object
show all
Defined in:
lib/asker/ai/problem/customizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(problem) ⇒ Customizer

Returns a new instance of Customizer.



4
5
6
# File 'lib/asker/ai/problem/customizer.rb', line 4

def initialize(problem)
  @problem = problem
end

Instance Method Details

#call(text:, custom:, type: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/asker/ai/problem/customizer.rb', line 8

def call(text:, custom:, type: nil)
  output = text.clone
  custom.each_pair { |oldvalue, newvalue| output.gsub!(oldvalue, newvalue) }
  
  if type.nil?
    return output 
  elsif type == "formula"
    begin
      return eval(output).to_s
    rescue SyntaxError => e
      Logger.error "Problem.name = #{@problem.name}"
      Logger.error "Customizer: Wrong formula '#{text}' or wrong values '#{output}'"
      Logger.error e.to_s
      exit 1
    end
  else
    Logger.error "Customizer: Wrong answer type (#{type})"
    exit 1
  end
end

#max(*args) ⇒ Object



33
34
35
# File 'lib/asker/ai/problem/customizer.rb', line 33

def max(*args)
  args.max
end

#min(*args) ⇒ Object



29
30
31
# File 'lib/asker/ai/problem/customizer.rb', line 29

def min(*args)
  args.min
end