lib/asker/data/problem.rb in asker-tool-2.7.2 vs lib/asker/data/problem.rb in asker-tool-2.8.0

- old
+ new

@@ -1,6 +1,7 @@ require_relative "../logger" +require_relative "../lang/lang_factory" class Problem attr_accessor :lang attr_accessor :context attr_accessor :process @@ -8,24 +9,26 @@ attr_accessor :varnames attr_accessor :cases attr_accessor :descs attr_accessor :asks attr_accessor :questions + attr_accessor :stats @@id = 0 def initialize @@id += 1 @id = @@id - @lang = nil + @lang = LangFactory.instance.get("en") @context = nil @process = false @filename = "?" @varnames = [] @cases = [] @descs = [] @asks = [] @questions = [] + @stats = { answer: 0, steps: 0} end def self.from(values) problem = Problem.new fields = %i[filename varnames cases descs asks] @@ -44,11 +47,12 @@ def process? @process end def name - "problem#{@id}" + firstword = @descs[0]&.strip&.split(" ")&.first&.downcase || "problem" + "#{firstword}#{@id}" end def validate validate_varnames validate_cases @@ -57,10 +61,12 @@ end private def validate_varnames + return if @varnames.nil? + if !@varnames.size.zero? && @cases.size.zero? Logger.warn "Problem: No problem/varnames defined with no problem/case" end @varnames.each_with_index do |varname1, index1| @@ -73,9 +79,11 @@ end end end def validate_cases + return if @cases.nil? + @cases.each do |acase| if acase.size != @varnames.size Logger.error "Problem: problem/cases size not equal to problem/varnames size" Logger.error " : cases size #{acase.size} (#{acase.join(",")})" Logger.error " : varnames size #{@varnames.size} (#{@varnames.join(",")})"