TESTS: Added more tests to the Reference parser

This commit is contained in:
jason.wall 2017-01-16 13:09:52 -05:00
parent 0ec22a09ee
commit 66b24edf27
2 changed files with 390 additions and 129 deletions

View File

@ -35,4 +35,256 @@ describe('Reference', () => {
it('Should parse the reference: 2 Samuel 5:5-6:5', () => {
expect(new Reference("II sam 5:5-6:5").toString()).toBe('2 Samuel 5:5 - 6:5');
});
let booknames = [
{ "abbr": "gen", "actual": "Genesis" },
{ "abbr": "ge", "actual": "Genesis" },
{ "abbr": "genesis", "actual": "Genesis" },
{ "abbr": "gn", "actual": "Genesis" },
{ "abbr": "exodus", "actual": "Exodus" },
{ "abbr": "ex", "actual": "Exodus" },
{ "abbr": "exo", "actual": "Exodus" },
{ "abbr": "exod", "actual": "Exodus" },
{ "abbr": "exd", "actual": "Exodus" },
{ "abbr": "leviticus", "actual": "Leviticus" },
{ "abbr": "lev", "actual": "Leviticus" },
{ "abbr": "le", "actual": "Leviticus" },
{ "abbr": "levi", "actual": "Leviticus" },
{ "abbr": "lv", "actual": "Leviticus" },
{ "abbr": "numbers", "actual": "Numbers" },
{ "abbr": "num", "actual": "Numbers" },
{ "abbr": "nu", "actual": "Numbers" },
{ "abbr": "numb", "actual": "Numbers" },
{ "abbr": "number", "actual": "Numbers" },
{ "abbr": "deuteronomy", "actual": "Deuteronomy" },
{ "abbr": "deut", "actual": "Deuteronomy" },
{ "abbr": "de", "actual": "Deuteronomy" },
{ "abbr": "dt", "actual": "Deuteronomy" },
{ "abbr": "deu", "actual": "Deuteronomy" },
{ "abbr": "joshua", "actual": "Joshua" },
{ "abbr": "josh", "actual": "Joshua" },
{ "abbr": "jos", "actual": "Joshua" },
{ "abbr": "judges", "actual": "Judges" },
{ "abbr": "jud", "actual": "Judges" },
{ "abbr": "jdg", "actual": "Judges" },
{ "abbr": "judg", "actual": "Judges" },
{ "abbr": "ruth", "actual": "Ruth" },
{ "abbr": "ru", "actual": "Ruth" },
{ "abbr": "1 samuel", "actual": "1 Samuel" },
{ "abbr": "1 sa", "actual": "1 Samuel" },
{ "abbr": "1 sam", "actual": "1 Samuel" },
{ "abbr": "1 sml", "actual": "1 Samuel" },
{ "abbr": "i samuel", "actual": "1 Samuel" },
{ "abbr": "i sa", "actual": "1 Samuel" },
{ "abbr": "i sam", "actual": "1 Samuel" },
{ "abbr": "i sml", "actual": "1 Samuel" },
{ "abbr": "1st samuel", "actual": "1 Samuel" },
{ "abbr": "1st sa", "actual": "1 Samuel" },
{ "abbr": "1st sam", "actual": "1 Samuel" },
{ "abbr": "1st sml", "actual": "1 Samuel" },
{ "abbr": "first samuel", "actual": "1 Samuel" },
{ "abbr": "first sa", "actual": "1 Samuel" },
{ "abbr": "first sam", "actual": "1 Samuel" },
{ "abbr": "first sml", "actual": "1 Samuel" },
{ "abbr": "2 samuel", "actual": "2 Samuel" },
{ "abbr": "2 sa", "actual": "2 Samuel" },
{ "abbr": "2 sam", "actual": "2 Samuel" },
{ "abbr": "2 sml", "actual": "2 Samuel" },
{ "abbr": "ii samuel", "actual": "2 Samuel" },
{ "abbr": "ii sa", "actual": "2 Samuel" },
{ "abbr": "ii sam", "actual": "2 Samuel" },
{ "abbr": "ii sml", "actual": "2 Samuel" },
{ "abbr": "2nd samuel", "actual": "2 Samuel" },
{ "abbr": "2nd sa", "actual": "2 Samuel" },
{ "abbr": "2nd sam", "actual": "2 Samuel" },
{ "abbr": "2nd sml", "actual": "2 Samuel" },
{ "abbr": "second samuel", "actual": "2 Samuel" },
{ "abbr": "second sa", "actual": "2 Samuel" },
{ "abbr": "second sam", "actual": "2 Samuel" },
{ "abbr": "second sml", "actual": "2 Samuel" },
{ "abbr": "sec samuel", "actual": "2 Samuel" },
{ "abbr": "sec sa", "actual": "2 Samuel" },
{ "abbr": "sec sam", "actual": "2 Samuel" },
{ "abbr": "sec sml", "actual": "2 Samuel" },
{ "abbr": "1 kings", "actual": "1 Kings" },
{ "abbr": "1 king", "actual": "1 Kings" },
{ "abbr": "1 kgs", "actual": "1 Kings" },
{ "abbr": "1 kn", "actual": "1 Kings" },
{ "abbr": "1 k", "actual": "1 Kings" },
{ "abbr": "1 ki", "actual": "1 Kings" },
{ "abbr": "i kings", "actual": "1 Kings" },
{ "abbr": "i king", "actual": "1 Kings" },
{ "abbr": "i kgs", "actual": "1 Kings" },
{ "abbr": "i kn", "actual": "1 Kings" },
{ "abbr": "i k", "actual": "1 Kings" },
{ "abbr": "i ki", "actual": "1 Kings" },
{ "abbr": "1st kings", "actual": "1 Kings" },
{ "abbr": "1st king", "actual": "1 Kings" },
{ "abbr": "1st kgs", "actual": "1 Kings" },
{ "abbr": "1st kn", "actual": "1 Kings" },
{ "abbr": "1st k", "actual": "1 Kings" },
{ "abbr": "1st ki", "actual": "1 Kings" },
{ "abbr": "first kings", "actual": "1 Kings" },
{ "abbr": "first king", "actual": "1 Kings" },
{ "abbr": "first kgs", "actual": "1 Kings" },
{ "abbr": "first kn", "actual": "1 Kings" },
{ "abbr": "first k", "actual": "1 Kings" },
{ "abbr": "first ki", "actual": "1 Kings" },
{ "abbr": "2 Kings", "actual": "2 Kings" },
{ "abbr": "2 king", "actual": "2 Kings" },
{ "abbr": "2 kgs", "actual": "2 Kings" },
{ "abbr": "2 kn", "actual": "2 Kings" },
{ "abbr": "2 k", "actual": "2 Kings" },
{ "abbr": "2 ki", "actual": "2 Kings" },
{ "abbr": "ii kings", "actual": "2 Kings" },
{ "abbr": "ii king", "actual": "2 Kings" },
{ "abbr": "ii kgs", "actual": "2 Kings" },
{ "abbr": "ii kn", "actual": "2 Kings" },
{ "abbr": "ii k", "actual": "2 Kings" },
{ "abbr": "ii ki", "actual": "2 Kings" },
{ "abbr": "2nd kings", "actual": "2 Kings" },
{ "abbr": "2nd king", "actual": "2 Kings" },
{ "abbr": "2nd kgs", "actual": "2 Kings" },
{ "abbr": "2nd kn", "actual": "2 Kings" },
{ "abbr": "2nd k", "actual": "2 Kings" },
{ "abbr": "2nd ki", "actual": "2 Kings" },
{ "abbr": "second kings", "actual": "2 Kings" },
{ "abbr": "second king", "actual": "2 Kings" },
{ "abbr": "second kgs", "actual": "2 Kings" },
{ "abbr": "second kn", "actual": "2 Kings" },
{ "abbr": "second k", "actual": "2 Kings" },
{ "abbr": "second ki", "actual": "2 Kings" },
{ "abbr": "sec kings", "actual": "2 Kings" },
{ "abbr": "sec king", "actual": "2 Kings" },
{ "abbr": "sec kgs", "actual": "2 Kings" },
{ "abbr": "sec kn", "actual": "2 Kings" },
{ "abbr": "sec k", "actual": "2 Kings" },
{ "abbr": "sec ki", "actual": "2 Kings" },
{ "abbr": "2 Chronicles", "actual": "2 Chronicles" },
{ "abbr": "2 chronicles", "actual": "2 Chronicles" },
{ "abbr": "2 chron", "actual": "2 Chronicles" },
{ "abbr": "2 ch", "actual": "2 Chronicles" },
{ "abbr": "2 chr", "actual": "2 Chronicles" },
{ "abbr": "ii Chronicles", "actual": "2 Chronicles" },
{ "abbr": "ii chronicles", "actual": "2 Chronicles" },
{ "abbr": "ii chron", "actual": "2 Chronicles" },
{ "abbr": "ii ch", "actual": "2 Chronicles" },
{ "abbr": "ii chr", "actual": "2 Chronicles" },
{ "abbr": "2nd Chronicles", "actual": "2 Chronicles" },
{ "abbr": "2nd chronicles", "actual": "2 Chronicles" },
{ "abbr": "2nd chron", "actual": "2 Chronicles" },
{ "abbr": "2nd ch", "actual": "2 Chronicles" },
{ "abbr": "2nd chr", "actual": "2 Chronicles" },
{ "abbr": "second Chronicles", "actual": "2 Chronicles" },
{ "abbr": "second chronicles", "actual": "2 Chronicles" },
{ "abbr": "second chron", "actual": "2 Chronicles" },
{ "abbr": "second ch", "actual": "2 Chronicles" },
{ "abbr": "second chr", "actual": "2 Chronicles" },
{ "abbr": "sec Chronicles", "actual": "2 Chronicles" },
{ "abbr": "sec chronicles", "actual": "2 Chronicles" },
{ "abbr": "sec chron", "actual": "2 Chronicles" },
{ "abbr": "sec ch", "actual": "2 Chronicles" },
{ "abbr": "sec chr", "actual": "2 Chronicles" },
{ "abbr": "1 Chronicles", "actual": "1 Chronicles" },
{ "abbr": "1 chronicles", "actual": "1 Chronicles" },
{ "abbr": "1 chron", "actual": "1 Chronicles" },
{ "abbr": "1 ch", "actual": "1 Chronicles" },
{ "abbr": "1 chr", "actual": "1 Chronicles" },
{ "abbr": "i Chronicles", "actual": "1 Chronicles" },
{ "abbr": "i chronicles", "actual": "1 Chronicles" },
{ "abbr": "i chron", "actual": "1 Chronicles" },
{ "abbr": "i ch", "actual": "1 Chronicles" },
{ "abbr": "i chr", "actual": "1 Chronicles" },
{ "abbr": "1st Chronicles", "actual": "1 Chronicles" },
{ "abbr": "1st chronicles", "actual": "1 Chronicles" },
{ "abbr": "1st chron", "actual": "1 Chronicles" },
{ "abbr": "1st ch", "actual": "1 Chronicles" },
{ "abbr": "1st chr", "actual": "1 Chronicles" },
{ "abbr": "first Chronicles", "actual": "1 Chronicles" },
{ "abbr": "first chronicles", "actual": "1 Chronicles" },
{ "abbr": "first chron", "actual": "1 Chronicles" },
{ "abbr": "first ch", "actual": "1 Chronicles" },
{ "abbr": "first chr", "actual": "1 Chronicles" },
{ "abbr": "ezra", "actual": "Ezra" },
{ "abbr": "ezr", "actual": "Ezra" },
{ "abbr": "nehemiah", "actual": "Nehemiah" },
{ "abbr": "neh", "actual": "Nehemiah" },
{ "abbr": "ne", "actual": "Nehemiah" },
{ "abbr": "nehamiah", "actual": "Nehemiah" },
{ "abbr": "esther", "actual": "Esther" },
{ "abbr": "est", "actual": "Esther" },
{ "abbr": "es", "actual": "Esther" },
{ "abbr": "esth", "actual": "Esther" },
{ "abbr": "job", "actual": "Job" },
{ "abbr": "jo", "actual": "Job" },
{ "abbr": "jb", "actual": "Job" },
{ "abbr": "psalms", "actual": "Psalm" },
{ "abbr": "ps", "actual": "Psalm" },
{ "abbr": "psa", "actual": "Psalm" },
{ "abbr": "psalm", "actual": "Psalm" },
{ "abbr": "psm", "actual": "Psalm" },
{ "abbr": "proverbs", "actual": "Proverbs" },
{ "abbr": "prov", "actual": "Proverbs" },
{ "abbr": "pr", "actual": "Proverbs" },
{ "abbr": "pro", "actual": "Proverbs" },
{ "abbr": "proverb", "actual": "Proverbs" },
{ "abbr": "prv", "actual": "Proverbs" },
{ "abbr": "prvbs", "actual": "Proverbs" },
{ "abbr": "ecclesiastes", "actual": "Ecclesiastes" },
{ "abbr": "eccl", "actual": "Ecclesiastes" },
{ "abbr": "ecc", "actual": "Ecclesiastes" },
{ "abbr": "eccles", "actual": "Ecclesiastes" },
{ "abbr": "ec", "actual": "Ecclesiastes" },
{ "abbr": "ecl", "actual": "Ecclesiastes" },
{ "abbr": "ecclesiaste", "actual": "Ecclesiastes" },
{ "abbr": "song of solomon", "actual": "Song of Solomon" },
{ "abbr": "song of songs", "actual": "Song of Solomon" },
{ "abbr": "sos", "actual": "Song of Solomon" },
{ "abbr": "ss", "actual": "Song of Solomon" },
{ "abbr": "son", "actual": "Song of Solomon" },
{ "abbr": "so", "actual": "Song of Solomon" },
{ "abbr": "song", "actual": "Song of Solomon" },
{ "abbr": "songs", "actual": "Song of Solomon" },
{ "abbr": "isaiah", "actual": "Isaiah" },
{ "abbr": "is", "actual": "Isaiah" },
{ "abbr": "isah", "actual": "Isaiah" },
{ "abbr": "isai", "actual": "Isaiah" },
{ "abbr": "ia", "actual": "Isaiah" },
{ "abbr": "jerimiah", "actual": "Jeremiah" },
{ "abbr": "jeremiah", "actual": "Jeremiah" },
{ "abbr": "jer", "actual": "Jeremiah" },
{ "abbr": "je", "actual": "Jeremiah" },
{ "abbr": "jere", "actual": "Jeremiah" },
{ "abbr": "lamentations", "actual": "Lamentations" },
{ "abbr": "lam", "actual": "Lamentations" },
{ "abbr": "la", "actual": "Lamentations" },
{ "abbr": "lamentation", "actual": "Lamentations" },
];
for (let bk of booknames) {
it('Should parse the references: ' + bk.abbr, () => {
let book = Reference.parseBook(bk.abbr);
expect(book.bookname).toBe(bk.actual);
for (let i = 1; i <= book.lastchapter; i++)
expect(new Reference(bk.abbr + ' ' + i).toString()).toBe(bk.actual + ' ' + i + ":1 - *");
for (let i = 1; i < book.lastchapter; i++)
expect(new Reference(bk.abbr + ' ' + i+'-'+(i+1)).toString()).toBe(bk.actual + ' ' + i + ":1 - "+(i+1)+":*");
expect(new Reference(bk.abbr + ' 1:4-2:5').toString()).toBe(bk.actual + ' 1:4 - 2:5');
expect(new Reference(bk.abbr + ' 1:1 - 5').toString()).toBe(bk.actual + ' 1:1 - 5');
expect(new Reference(bk.abbr + ' 1:4 - 5').toString()).toBe(bk.actual + ' 1:4 - 5');
});
}
let refs = [
{ "src": "2 sam 3:4-6:8", "actual": "2 Samuel 3:4 - 6:8" },
//{ "src": "gen 50 - ex 2", "actual": "Genesis 50:1 - Exodus 2:*" },
];
for (let ref of refs) {
it('Should parse the reference: ' + ref.src, () => {
expect(new Reference(ref.src).toString()).toBe(ref.actual);
});
}
});

View File

@ -58,7 +58,7 @@ export class Reference {
Number(this.Section.start.verse) > Number(this.Section.end.verse) &&
this.Section.start.chapter == this.Section.end.chapter &&
this.Section.start.book == this.Section.end.book
) this.Section.end.verse = this.Section.start.verse;
) this.Section.end.verse = this.Section.start.verse;
if (this.Section.start.verse == "") this.Section.start.verse = "1";
if (this.Section.end.verse == "") this.Section.end.verse = "*";
}
@ -78,14 +78,136 @@ export class Reference {
private parseBook(isEnd?: boolean) {
this.ref = this.ref.toLowerCase().trim();
let thing = this.Section.start;
if (isEnd) thing = this.Section.end;
let fbook = this.ref.substring(0, this.ref.search(/\w\s+\d/i) + 1);
if (!fbook)
fbook = this.ref;
this.ref = this.ref.slice(this.ref.search(/\w\s+\d/i) + 1);
if (isEnd) this.Section.end = Reference.parseBook(fbook);
else this.Section.start = Reference.parseBook(fbook);
}
private parseFirstNum(isEnd: boolean) {
let thing = this.Section.start;
if (isEnd) thing = this.Section.end;
this.ref = StringUtils.ltrim(this.ref);
let found = false;
for (let i = 0; i <= this.ref.length; i++) {
let c = this.ref.charAt(i);
// Grab characters until we hit a non digit.
if ("0".charAt(0) <= c && c <= "9".charAt(0)) {
found = true;
thing.chapter = thing.chapter.concat(c);
} else {
// if the chapter is longer than 3 digits it's an error
if (thing.chapter.length > 3) {
this.errAcc = "Chapter too long\"" + thing.chapter + "\".";
return;
} else if (!found) {
this.errAcc = "No chapter found" + this.ref;
}
this.ref = this.ref.slice(i);
return;
}
}
}
private parseSecondNum(skipColon?: boolean, isEnd?: boolean) {
let thing = this.Section.start;
if (isEnd) thing = this.Section.end;
this.ref = StringUtils.ltrim(this.ref.toLowerCase());
if (!skipColon) {
if (this.ref[0] != ":") {
return;
}
this.ref = this.ref.slice(1);
}
this.ref = StringUtils.ltrim(this.ref.toLowerCase());
if (this.ref[0] == "*") {
thing.verse = "*";
this.ref = this.ref.slice(1);
return;
}
for (var i = 0; i <= this.ref.length; i++) {
let c = this.ref.charAt(i);
if ("0".charAt(0) <= c && c <= "9".charAt(0)) {
thing.verse = thing.verse.concat(c);
} else {
if (thing.verse.length > 3) {
this.errAcc = "Verse too long \"" + thing.verse + "\".";
return "";
}
this.ref = this.ref.slice(i);
return;
}
}
}
private maybeParseBook(isEnd: boolean) {
return this.maybeDo(() => {
if (this.ref.search(/\w\s+\d/i) == -1) {
this.Section.end.book = this.Section.start.book;
this.Section.end.bookname = this.Section.start.bookname;
this.Section.end.longbookname = this.Section.start.longbookname;
this.Section.end.lastchapter = this.Section.start.lastchapter;
}
else {
this.parseBook(isEnd)
}
});
};
private maybeParseSecondNum(isEnd?: boolean) {
return this.maybeDo(() => {
this.parseSecondNum(false, isEnd);
});
};
private maybeParseFirstNumOrVerse(foundSecondBook: boolean, foundFirstVerse: boolean, isEnd: boolean) {
let self = this;
return this.maybeDo(() => {
if (self.Section.end.book == self.Section.start.book) {
if (self.ref.search(/:/) != -1 || foundSecondBook || !foundFirstVerse) {
self.parseFirstNum(isEnd);
}
self.parseSecondNum(true, isEnd);
}
});
};
private maybeParseRangeSep() {
let self = this;
return this.maybeDo(() => {
if (self.ref[0] == "-") {
self.ref = StringUtils.ltrim(self.ref.slice(1));
}
});
};
private maybeDo(f) {
let func = f;
this.ref = StringUtils.ltrim(this.ref.toLowerCase());
if (this.ref != "") {
func();
}
};
public toString() {
// get the starting book, chapter, verse
return Reference.toString(this.Section);
};
public static parseBook(fbook: string) {
let thing = {
book: 0,
bookname: "",
longbookname: "",
lastchapter: 0,
chapter: "",
verse: ""
};
if (fbook.search(/\b(genesis|gen|ge|gn)\b/i) != -1) {
thing.book = 1;
thing.bookname = "Genesis";
@ -122,7 +244,7 @@ export class Reference {
thing.longbookname = "Book_of_Joshua";
thing.lastchapter = 24;
}
if (fbook.search(/\b(judges|jud|ju|jdg|judg)\b/i) != -1) {
if (fbook.search(/\b(judges|jud|jdg|judg)\b/i) != -1) {
thing.book = 7;
thing.bookname = "Judges";
thing.longbookname = "Book_of_Judges";
@ -170,7 +292,7 @@ export class Reference {
thing.longbookname = "Second_Chronicles";
thing.lastchapter = 36;
}
if (fbook.search(/\b(ezra|ez|ezr)\b/i) != -1) {
if (fbook.search(/\b(ezra|ezr)\b/i) != -1) {
thing.book = 15;
thing.bookname = "Ezra";
thing.longbookname = "Book_of_Ezra";
@ -218,7 +340,7 @@ export class Reference {
thing.longbookname = "Song_of_Solomon";
thing.lastchapter = 8;
}
if (fbook.search(/\b(isaiah|is|is|isah|isai|ia)\b/i) != -1) {
if (fbook.search(/\b(isaiah|is|isah|isai|ia)\b/i) != -1) {
thing.book = 23;
thing.bookname = "Isaiah";
thing.longbookname = "Book_of_Isaiah";
@ -236,7 +358,7 @@ export class Reference {
thing.longbookname = "Book_of_Lamentations";
thing.lastchapter = 5;
}
if (fbook.search(/\b(ezekiel|eze|ez|ezk|ezek)\b/i) != -1) {
if (fbook.search(/\b(ezekiel|eze|ezk|ezek)\b/i) != -1) {
thing.book = 26;
thing.bookname = "Ezekiel";
thing.longbookname = "Book_of_Ezekiel";
@ -470,7 +592,7 @@ export class Reference {
thing.longbookname = "Third_Epistle_of_John";
thing.lastchapter = 1;
}
if (fbook.search(/\b(jude|jud|ju)\b/i) != -1) {
if (fbook.search(/\b(jude|ju)\b/i) != -1) {
thing.book = 65;
thing.bookname = "Jude";
thing.longbookname = "Epistle_of_Jude";
@ -482,122 +604,11 @@ export class Reference {
thing.longbookname = "Book_of_Revelations";
thing.lastchapter = 22;
}
return thing;
}
private parseFirstNum(isEnd: boolean) {
let thing = this.Section.start;
if (isEnd) thing = this.Section.end;
this.ref = StringUtils.ltrim(this.ref);
let found = false;
for (let i = 0; i <= this.ref.length; i++) {
let c = this.ref.charAt(i);
// Grab characters until we hit a non digit.
if ("0".charAt(0) <= c && c <= "9".charAt(0)) {
found = true;
thing.chapter = thing.chapter.concat(c);
} else {
// if the chapter is longer than 3 digits it's an error
if (thing.chapter.length > 3) {
this.errAcc = "Chapter too long\"" + thing.chapter + "\".";
return;
} else if (!found) {
this.errAcc = "No chapter found" + this.ref;
}
this.ref = this.ref.slice(i);
return;
}
}
}
private parseSecondNum(skipColon?: boolean, isEnd?: boolean) {
let thing = this.Section.start;
if (isEnd) thing = this.Section.end;
this.ref = StringUtils.ltrim(this.ref.toLowerCase());
if (!skipColon) {
if (this.ref[0] != ":") {
return;
}
this.ref = this.ref.slice(1);
}
this.ref = StringUtils.ltrim(this.ref.toLowerCase());
if (this.ref[0] == "*") {
thing.verse = "*";
this.ref = this.ref.slice(1);
return;
}
for (var i = 0; i <= this.ref.length; i++) {
let c = this.ref.charAt(i);
if ("0".charAt(0) <= c && c <= "9".charAt(0)) {
thing.verse = thing.verse.concat(c);
} else {
if (thing.verse.length > 3) {
this.errAcc = "Verse too long \"" + thing.verse + "\".";
return "";
}
this.ref = this.ref.slice(i);
return;
}
}
}
private maybeParseBook(isEnd: boolean) {
return this.maybeDo(() => {
if (this.ref.search(/\w\s+\d/i) == -1) {
this.Section.end.book = this.Section.start.book;
this.Section.end.bookname = this.Section.start.bookname;
this.Section.end.longbookname = this.Section.start.longbookname;
this.Section.end.lastchapter = this.Section.start.lastchapter;
}
else {
this.parseBook(isEnd)
}
});
};
private maybeParseSecondNum(isEnd?: boolean) {
return this.maybeDo(() => {
this.parseSecondNum(false, isEnd);
});
};
private maybeParseFirstNumOrVerse(foundSecondBook: boolean, foundFirstVerse: boolean, isEnd: boolean) {
let self = this;
return this.maybeDo(() => {
if (self.Section.end.book == self.Section.start.book) {
if (self.ref.search(/:/) != -1 || foundSecondBook || !foundFirstVerse) {
self.parseFirstNum(isEnd);
}
self.parseSecondNum(true, isEnd);
}
});
};
private maybeParseRangeSep() {
let self = this;
return this.maybeDo(() => {
if (self.ref[0] == "-") {
self.ref = StringUtils.ltrim(self.ref.slice(1));
}
});
};
private maybeDo(f) {
let func = f;
this.ref = StringUtils.ltrim(this.ref.toLowerCase());
if (this.ref != "") {
func();
}
};
public toString() {
// get the starting book, chapter, verse
return Reference.toString(this.Section);
};
public static toString(section: Section)
{
public static toString(section: Section) {
// get the starting book, chapter, verse
let ref = section.start.bookname.concat(" ").
concat(section.start.chapter).concat(":").
@ -605,15 +616,13 @@ export class Reference {
if (section.start.chapter == section.end.chapter &&
section.start.verse == section.end.verse &&
section.start.book == section.end.book)
{
section.start.book == section.end.book) {
return ref;
}
if (section.start.chapter == section.end.chapter &&
section.start.verse != section.end.verse &&
section.start.book == section.end.book)
{
section.start.book == section.end.book) {
return ref.concat(" - ").concat(section.end.verse);
}