「モジュール:SMWメンバー情報」の版間の差分

提供:エケペディア
ナビゲーションに移動 検索に移動
(ページの作成:「local p = {} local function setProperty(dataStore) -- メイン空間のみ if not mw.title.getCurrentTitle().namespace == 0 then return true; end if not mw.smw then return true; end local result = mw.smw.set( dataStore ) if result == true then -- everything ok else -- error message to be found in result.error end end local function test(frame) local args = frame.args --local args = require( 'Module:Argum…」)
 
編集の要約なし
90行目: 90行目:
function p.main(frame)
function p.main(frame)
   local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:メンバー情報', removeBlanks = false, parentFirst = true });
   local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:メンバー情報', removeBlanks = false, parentFirst = true });
 
  local dataStore = {}
   -- 選抜回数
   -- 選抜回数
   dataStore["選抜回数"] = {}
   dataStore["選抜回数"] = {}

2023年7月22日 (土) 21:14時点における版

このモジュールについての説明文ページを モジュール:SMWメンバー情報/doc に作成できます

local p = {}

local function setProperty(dataStore)
   -- メイン空間のみ
   if not mw.title.getCurrentTitle().namespace == 0 then
      return true;
   end

   if not mw.smw then
      return true;
   end

   local result = mw.smw.set( dataStore )

   if result == true then
      -- everything ok
   else
      -- error message to be found in result.error
   end
end

local function test(frame)
   local args = frame.args
   --local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:メンバー情報', removeBlanks = false, parentFirst = true });

   local dataStore = {}
   dataStore["主チーム"] = args["チーム"] or ""
   dataStore["主な元グループ"] = args["チーム"] or ""
   dataStore["主チーム"] = args["チーム"] or ""
   dataStore["出身地"] = args["出身地"] or ""
   dataStore["生年月日"] = args["生年月日"] or ""
   dataStore["血液型"] = mw.text.unstrip(args["血液型"] or "")
   dataStore["合格期"] = args["合格期"] or ""
   dataStore["名前"] = args["名前"] or ""
   dataStore["読み"] = args["読み"] or ""
   dataStore["公式ニックネーム"] = args["公式ニックネーム"] or ""
   dataStore["所属事務所"] = args["所属事務所"] or ""
   dataStore["身長"] = mw.text.unstrip(args["身長"] or "")
   dataStore["お披露目日"] = args["お披露目日"] or ""
   dataStore["卒業発表日"] = args["卒業発表日"] or ""
   dataStore["最終活動日"] = args["最終活動日"] or ""
   dataStore["昇格日"] = args["昇格日"] or ""
   -- グループの処理
   local group_keys = {"グループ", "グループ2", "グループ3"}
   dataStore["グループ"] = {}
   for _, key in ipairs(group_keys) do
      local group_value = args[key]
      if group_value and group_value ~= "" then
         table.insert(dataStore["グループ"], group_value)
      end
   end
   -- チームの処理
   local team_keys = {"チーム", "チーム2", "チーム3"}
   dataStore["チーム"] = {}
   for _, key in ipairs(team_keys) do
      local team_value = args[key]
      if team_value and team_value ~= "" then
         table.insert(dataStore["チーム"], team_value)
      end
   end
   -- 選抜回数
   dataStore["選抜回数"] = {}

   local lines = mw.text.split(args["選抜回数"]or "", '<br>')
   mw.logObject(lines)
   local total = 0
   -- Iterate over the lines
   for _, line in ipairs(lines) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      mw.logObject(mw.ustring.match(line, "(.+) (%d+)回"))
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["グループ"] or ""
      end
      -- If the num is nil, return an error
      if not num then
         return nil, "Unable to extract number from line: " .. line
      end
      -- Store the group and selection times
      total = total + tonumber(num)
      table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
   end
   -- Add the total selection times to the dataStore
   dataStore["選抜回数合計"] = total

   local generation = ''
   return dataStore;
end

function p.main(frame)
   local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:メンバー情報', removeBlanks = false, parentFirst = true });
   local dataStore = {}
   -- 選抜回数
   dataStore["選抜回数"] = {}

   local lines = mw.text.split(args["選抜回数"]or "", '<br>')
   mw.logObject(lines)
   local total = 0
   -- Iterate over the lines
   for _, line in ipairs(lines) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      mw.logObject(mw.ustring.match(line, "(.+) (%d+)回"))
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["グループ"] or ""
      end
      -- If the num is nil, return an error
      if not num then
         return nil, "Unable to extract number from line: " .. line
      end
      -- Store the group and selection times
      total = total + tonumber(num)
      table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
   end
   -- Add the total selection times to the dataStore
   dataStore["選抜回数合計"] = total
   setProperty(dataStore);
   return nil;
end

return p