DKL9 GitList
Repositories
DKL9 home
memoire
Code
Commits
Branches
Tags
Search
Tree:
f34deee
Branches
Tags
master
memoire
prompt.lua
Adds Prompt library
John Smith
commited
f34deee
at 2021-310 00:40:44
prompt.lua
Blame
History
Raw
--[[ a prompt consists of prompt text (with an answer-insertion point), a correct answer, the review timestamp, and the review delay ]] local Prompt = {} Prompt.__index = Prompt --[[ the answer-insertion point is indicated with a %A in the prompt text ]] function Prompt:new(pt, ca, rts, rd) local o = {} setmetatable(o, self) o.text = pt o.ans = ca o.time = tonumber(rts) o.delay = tonumber(rd) return o end function Prompt:__tostring() return string.format("\"%s\" (\"%s\") %d+%d", self.text, self.ans, self.time, self.delay) end --[[ extracts prompts from a record-based deck returns (on success) a table of Prompts returns (on failure) nil ]] function Prompt:fromrecs(recs) local ret = {} for _i, rec in ipairs(recs) do -- only bother with records with PromptText if rec.PromptText then local opt = rec.PromptText[1] local m, n = opt:find "%{[^%}]+%}" local ctr = 1 while m do local mpt = (opt:sub(1, m - 1) .. "%A" .. opt:sub(n + 1)):gsub("%{([^%}]+)%}", "%1") table.insert(ret, Prompt:new(mpt, opt:sub(m + 1, n - 1), (rec.LastReview or {})[ctr], (rec.LastDelay)[ctr])) m, n = opt:find("%{[^%}]+%}", n) ctr = ctr + 1 end end end return ret end return Prompt