Module:Chapter to volume

-- Do not remove this comment; it prevents accidental categorization of this page -- determines the volume number from the chapter number -- takes two arguments: 1st series (re or tg), 2nd chapter number -- outputs the volume number

local m = {};

-- computes the TG volume from the chapter number local function gettgvolume(chapter) if string.lower(chapter) == "rize" then return 5; end chapter = tonumber(chapter); if not chapter or chapter 143 then return "Error: Invalid chapter"; end local volume; if chapter >= 90 then if chapter > 121.5 then chapter = chapter + 1; end volume = math.floor(((chapter - 90) + 0.5) / 11) + 10; else volume = math.floor((chapter + 0.5) / 10) + 1; if chapter >= 40 and chapter <= 70 and (chapter % 10) == 9 then volume = volume + 1; end end return volume; end

-- computes the re volume from the chapter number local function getrevolume(chapter) if string.lower(chapter) == "joker" then return 3; end chapter = tonumber(chapter); if not chapter or chapter 143 then return "Error: Invalid chapter"; end -- handle that volume 4 contains 10 chapters if chapter >= 31.5 then chapter = chapter + 1; end -- + 1.5 because volume 1 contains 10 chapters instead of 11 local volume = math.floor((chapter + 1.5) / 11) + 1;

return volume; end

-- public function function m.getvolume(frame) local args = frame.args; local series = args[1]; local chapter = args[2]; if series == "tg" then return tostring(gettgvolume(chapter)); elseif series == "re" then return tostring(getrevolume(chapter)); else return "Error: Invalid series"; end end

return m;

-- see comment at top