FANDOM


--[[
This is a test module for looking up Bible verses from a supplied edition, book name, chapter, and verse
--]]
 
errors = {
      "No edition / version specified. You must specify a version!",
      "Edition / version not found or currently not implemented. Valid versions are:<br />&bull;'''King James Version (or KJV)'''",
      "No book specified. You must specify a book!",
      "Book not found in edition. Please check the spelling of the name.",
      "You must specify either a valid chapter number, such as ''chapter=#'', or a chapter-verse string, such as ''##:##''",
      "Invalid chapter number. Chapter number is either too high or a negative / zero value",
      "You must specify either a valid verse number, such as ''verse=#'', or a chapter-verse string, such as ''##:##''",
      "Verse not found!",
}
 
local p = {}
 
function p.bibleverse ( frame )
 
   local edition = frame.args[1] or frame.args['edition']
   local book = frame.args[2] or frame.args['book']
   local chapter = p.ExtractChapterNumber( frame.args[3] ) or tonumber( frame.args['chapter'] )
   local verse = p.ExtractVerseNumber ( frame.args[3] ) or tonumber ( frame.args['verse'] )
 
   if not edition then
      return errors[1]
   end
 
   local validedition = p.StandardizeEditionName( edition )
 
   if not validedition then
      return errors[2]
   end
 
   local edition = validedition
 
   if not book then
      return errors[3]
   end
 
   local validbook = p.StandardizeBookName( edition, book )
 
   if not validbook then
      return errors[4]
   end
 
   local book = validbook
 
   if not chapter then
      return errors[5]
   end
 
   local validchapter = p.TestMaxChapterNumber ( edition, book, chapter )
 
   if not validchapter then
      return errors[6]
   end
 
   if not verse then
      return errors[7]
   end
 
   retrievedverse = p.RetrieveVerse ( edition, book, chapter, verse )
 
   if not retrievedverse then
      return errors[8]
   else
      return string.format( "'''%s %s:%s (%s)''' - ''%s''<br /><br />", book, chapter, verse, edition, retrievedverse )
   end
 
end
 
 
function p.StandardizeEditionName ( edition )
 
   local editionnames = {
 
      ["KJV"]                  =   "King James Version",
      ["KING JAMES VERSION"]   =   "King James Version",
      ["AV"]                   =   "King James Version",
 
   }
 
   local edition = mw.ustring.upper( edition )
 
   local standardizedname = editionnames[edition]
 
   return standardizedname
 
end
 
function p.StandardizeBookName ( edition, book )
 
   local book = mw.ustring.upper ( book )
 
   local booknames = mw.loadData( 'Module:Bible/' .. edition .. '/ValidBookNames' )
 
   local standardizedbookname = booknames[book]
 
   return standardizedbookname
 
end
 
function p.ExtractChapterNumber ( chapterversestring )
 
   if not chapterversestring then
      return nil
   end
 
   local chapterstring = mw.ustring.gsub( chapterversestring, '(.+):.+', '%1' )
   local chapternumber = tonumber( chapterstring )
 
   return chapternumber
 
end
 
function p.ExtractVerseNumber ( chapterversestring )
 
   if not chapterversestring then
      return nil
   end
 
   local versestring = mw.ustring.gsub( chapterversestring, '^.+:(.+)', '%1' )
   local versenumber = tonumber( versestring )
 
   return versenumber
 
end
 
function p.TestMaxChapterNumber ( edition, book, chapter )
 
   local chapternumbers = mw.loadData( 'Module:Bible/' .. edition .. '/ValidMaxChapter' )
 
   local maxchapter = tonumber( chapternumbers[book] )
 
   if chapter < 0 then
      return false
   elseif chapter > maxchapter then
      return false
   else
      return true
   end
 
end
 
function p.RetrieveVerse ( edition, book, chapter, verse )
 
   local chapter = tostring( chapter )
   local verse = tostring( verse )
   local chapterversestring = chapter .. ':' .. verse
   local verselist = mw.loadData( 'Module:Bible/' .. edition .. '/' .. book )
   local retrievedverse = verselist[chapterversestring]
 
   return retrievedverse
 
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.