[sword-devel] Getting info about books, chapters, and verses in a module

Tobias Klein contact at tklein.info
Sat Nov 28 14:59:29 EST 2020

Hi Troy,

Thanks once more for highlighting the code smells as you did! :)

In node-sword-interface, I have now implemented two new helper methods 
and getChapterVerseCount. 
These methods use the getChapterMax() and getVerseMax() functions from 

Based on my new helper methods, I then refactored my code in the 
frontend a bit and saw a decent performance improvement after that 
(saving 800ms on startup time when directly loading a book).

Best regards,

On 11/18/20 7:53 AM, Tobias Klein wrote:
>> I am note sure I condone this behavior here :)  If you found a need 
>> to do something like this because you couldn't easily use the 
>> suggestions below, please let me know and maybe we can fix something 
>> or extend functionality to meet your needs.
>> If you ever want to know how many Books, Chapters, Verses, etc. are 
>> available in a reference system, these should serve that purpose:
>> VerseKey::getTestamentMax()
>> VerseKey::getBookMax(), once you set the testament
>> VerseKey::getChapterMax(), once you set the book
>> VerseKey::getVerseMax(), once you set the chapter
> At the time when I wrote that function I didn't realize that I could 
> use VerseKey to determine max values of chapters/chapter-verses per book.
> Thanks! I may actually refactor my code now based on your hint.
> To give you some context how I use this function ... in Ezra Project, 
> this is currently used in three places.
> 1) NavigationPane => Getting the number of chapters for a book
> 2) I have a "verse range formatter", that needs the verse count per 
> chapter to work correctly.
> 3) In my TagStatistics function I calculate percentages relative to 
> the total number of verses in a book.
> Best regards,
> Tobias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://crosswire.org/pipermail/sword-devel/attachments/20201128/3bc3fe92/attachment.html>

More information about the sword-devel mailing list