You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

29 lines
558 B

class Player < ApplicationRecord
# progress shape:
# { "1" => { "answer_id" => 42, "result_id" => 99 }, "2" => { ... } }
def record_answer(stage, answer_id)
stage_data(stage)["answer_id"] = answer_id
save
end
def record_result(stage, result_id)
stage_data(stage)["result_id"] = result_id
save
end
def answer_id_for(stage)
progress[stage.to_s]&.dig("answer_id")
end
def result_id_for(stage)
progress[stage.to_s]&.dig("result_id")
end
private
def stage_data(stage)
progress[stage.to_s] ||= {}
end
end