モジュール:SMWメンバー情報

提供:エケペディア
ナビゲーションに移動 検索に移動

このモジュールについての説明文ページを モジュール: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["血液型"] = 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_s = mw.text.split(args["選抜回数"] or "", '<br>')
   mw.logObject(lines_s)
   local total_s = 0
   -- Iterate over the lines_s
   for _, line in ipairs(lines_s) 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 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
      if tonumber(num) > 0 then
        total_s = total_s + tonumber(num)
        table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
      end
   end
   -- Add the total selection times to the dataStore
   dataStore["選抜回数合計"] = total_s

   -- センター回数
   dataStore["選抜回数"] = {}

   local lines_c = mw.text.split(args["センター回数"] or "", '<br>')
   mw.logObject(lines_c)
   local total_c = 0
   -- Iterate over the lines_c
   for _, line in ipairs(lines_c) 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 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
      if  tonumber(num) > 0 then
        total_c = total_c + tonumber(num)
        table.insert(dataStore["センター回数"], extractedGroup .. ';' .. num)
      end
   end
   -- Add the total selection times to the dataStore
   if total_c > 0 then
     dataStore["センター回数合計"] = total_c
   end

   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_s = mw.text.split(args["選抜回数"] or "", '<br>')
   mw.logObject(lines_s)
   local total_s = 0
   -- Iterate over the lines_s
   for _, line in ipairs(lines_s) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["元グループ"] or args["グループ"] or ""
         num = mw.ustring.match(line, "(%d+)回")
      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
      if tonumber(num) > 0 then
        total_s = total_s + tonumber(num)
        table.insert(dataStore["選抜回数"], extractedGroup .. ';' .. num)
      end
   end
   -- Add the total selection times to the dataStore
   dataStore["選抜回数合計"] = total_s
   setProperty(dataStore);

   -- センター回数
   dataStore["センター回数"] = {}

   local lines_c = mw.text.split(args["センター回数"] or "", '<br>')
   mw.logObject(lines_c)
   local total_c = 0
   -- Iterate over the lines_c
   for _, line in ipairs(lines_c) do
      local extractedGroup, num = mw.ustring.match(line, "(.+) (%d+)回")
      -- If the group is not extracted, use the provided group
      if not extractedGroup or extractedGroup == "" then
         extractedGroup = args["元グループ"] or args["グループ"] or ""
         num = mw.ustring.match(line, "(%d+)回")
      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
      if tonumber(num) > 0 then
        total_c = total_c + tonumber(num)
        table.insert(dataStore["センター回数"], extractedGroup .. ';' .. num)
      end
   end
   -- Add the total selection times to the dataStore

   if total_c > 0 then
     dataStore["センター回数合計"] = total_c
   end

   setProperty(dataStore);

   return nil;
end

return p