class Player < ApplicationRecord attribute :progress, :json, default: {} attribute :current_stage, :integer, default: 1 attribute :score, :integer, default: 0 # stage_index: 1, 2, 3... # outcome: 'chance' or 'choice' def record_flip(stage_index, outcome) self.progress[stage_index.to_s] ||= {} self.progress[stage_index.to_s]["flip"] = outcome save end # stage_index: 1, 2, 3... # option_index: 1, 2, or 3 def record_option(stage_index, option_index) self.progress[stage_index.to_s] ||= {} self.progress[stage_index.to_s]["option"] = option_index save end def advance_to_next_stage! self.current_stage += 1 save end end