Module:Volume

From Pittsburgh Streets

Documentation for this module may be created at Module:Volume/doc

local p = {};

function p.volume(frame)
  local v = frame.args[1];
  if not v then
    return '';
  end
  local _, prefix_end, prefix = v:find('^%s*%(([^%)]*)%)%s*');
  local note_start, _, note = v:find('%s*%(([^%)]*)%)%s*$', (prefix_end or 0) + 1);
  local number = v:sub((prefix_end or 0) + 1, (note_start or #v + 1) - 1);
  if number == '' then
    return '';
  end
  local result = '';
  if prefix then
    result = prefix .. ' ';
  end
  if number:sub(1, 1) == '[' and number:sub(-1) == ']' then
    result = result .. '[vol. ' .. number:sub(2, -2) .. ']';
  else
    result = result .. 'vol. ' .. number;
  end
  if note then
    result = result .. ' (' .. note .. ')';
  end
  return result;
end

return p;