יחידה:גימטריה
היחידה גימטריה מייצאת מספר פונקציות. שתי העיקריות הן "גימטריה" שמתמירה מחרוזת למספר המייצג את ערך המחרוזת בגימטריה, ו"מספר לאותיות" שעושה את הפעולה ההפוכה.
דוגמה:
{{#invoke:גימטריה|גימטריה|מטאטא חדש מנקה טוב}}=> 584{{#invoke:גימטריה|גימטריה|ה'תשעד}}=> 5774{{#invoke:גימטריה|גימטריה|ה'תשע"ד}}=> 5774
"מספר לאותיות" פונקציע:
{{#invoke:גימטריה|מספר לאותיות|877}}=> תתעז{{#invoke:גימטריה|מספר לאותיות|15}}=> טו{{#invoke:גימטריה|מספר לאותיות|16}}=> טז{{#invoke:גימטריה|מספר לאותיות|5786}}=> תתתתתתתתתתתתתתקפו
ניתן להעביר לפונקציה מספר לאותיות פרמטר שני, בדרך כלל ' או ", (אבל אפשר להעביר מה שרוצים). אם קיים פרמטר כזה, הוא ייתווסף לפני האות האחרונה של המחרוזת המוחזרת:
{{#invoke:גימטריה|מספר לאותיות|773|"}}=> תשע"ג
יש לשים לב: אם הפרמטר האחרון כולל רווחים, גם אלו יתווספו למחרוזת:
{{#invoke:גימטריה|מספר לאותיות|773| " }}=> תשע " ג
local values = {
['א'] = 1,
['ב'] = 2,
['ג'] = 3,
['ד'] = 4,
['ה'] = 5,
['ו'] = 6,
['ז'] = 7,
['ח'] = 8,
['ט'] = 9,
['י'] = 10,
['כ'] = 20,
['ל'] = 30,
['מ'] = 40,
['נ'] = 50,
['ס'] = 60,
['ע'] = 70,
['פ'] = 80,
['צ'] = 90,
['ק'] = 100,
['ר'] = 200,
['ש'] = 300,
['ת'] = 400,
}
local tab = {}
for k, v in pairs( values ) do tab[v] = k end
local endet = {
['ך'] = 20,
['ם'] = 40,
['ן'] = 50,
['ף'] = 80,
['ץ'] = 90,
}
local gimatria = function(s)
-- Check for a thousands separator (apostrophe)
local thousands, rest = s:match("^(.-)'(.*)$")
if thousands then
local total = 0
local thousandsValue = 0
-- Calculate gematria for the thousands part
for l in mw.ustring.gmatch(thousands, ".") do
thousandsValue = thousandsValue + (values[l] or endet[l] or 0)
end
total = thousandsValue * 1000
-- Add gematria for the rest of the number (ignoring extra apostrophes)
for l in mw.ustring.gmatch(rest, ".") do
total = total + (values[l] or endet[l] or 0)
end
return total
else
local total = 0
for l in mw.ustring.gmatch(s, ".") do
total = total + (values[l] or endet[l] or 0)
end
return total
end
end
local mispar_lotiot = function( num, geresh )
local res, toadd = '', 0
while num > 0 do
if num >= 400 then toadd = 400
elseif num >= 100 then toadd = num - num % 100
elseif num >= 10 then toadd = num - num % 10
else toadd = num end
res = res .. tab[toadd]
num = num - toadd
end
res = mw.ustring.gsub( res, 'יה', 'טו' )
res = mw.ustring.gsub( res, 'יו', 'טז' )
res = mw.ustring.gsub( res, '(.)(.)$', '%1' .. (geresh or '') .. '%2' )
return res
end
local haba = function(s)
return mispar_lotiot(gimatria(s)+1, '')
end
local haqodem = function(s)
return mispar_lotiot(gimatria(s)-1, '')
end
return {
gimatria = gimatria,
['גימטריה'] = function( frame )
return gimatria(frame.args[1] or '')
end,
mispar_lotiot = mispar_lotiot,
['מספר לאותיות'] = function( frame )
return mispar_lotiot( (tonumber(frame.args[1]) or 0), ( frame.args[2] or '' ))
end,
}