move book one level up in reference

This commit is contained in:
Jason Wall 2020-08-06 20:18:38 -04:00
parent 26ad51c57f
commit cdb54947cb
2 changed files with 21 additions and 46 deletions

View File

@ -20,13 +20,12 @@ class StringUtils {
export class BibleReference {
constructor(reference: string) {
this.Section = {
book: null,
start: {
book: null,
chapter: '',
verse: '',
},
end: {
book: null,
chapter: '',
verse: '',
},
@ -34,17 +33,12 @@ export class BibleReference {
this.ref = reference.toLowerCase().trim();
this.parseReference();
if (this.Section.end.book === null) {
this.Section.end.book = this.Section.start.book;
}
if (this.Section.end.chapter === '') {
this.Section.end.chapter = this.Section.start.chapter;
}
if (
Number(this.Section.start.verse) > Number(this.Section.end.verse) &&
this.Section.start.chapter === this.Section.end.chapter &&
this.Section.start.book.name === this.Section.end.book.name
this.Section.start.chapter === this.Section.end.chapter
) {
this.Section.end.verse = this.Section.start.verse;
}
@ -1870,7 +1864,7 @@ export class BibleReference {
public static toString(section: Section) {
// get the starting book, chapter, verse
let ref = section.start.book.name
let ref = section.book.name
.concat(' ')
.concat(section.start.chapter)
.concat(':')
@ -1878,25 +1872,19 @@ export class BibleReference {
if (
section.start.chapter === section.end.chapter &&
section.start.verse === section.end.verse &&
section.start.book.name === section.end.book.name
section.start.verse === section.end.verse
) {
return ref;
}
if (
section.start.chapter === section.end.chapter &&
section.start.verse !== section.end.verse &&
section.start.book.name === section.end.book.name
section.start.verse !== section.end.verse
) {
return ref.concat(' - ').concat(section.end.verse);
}
if (section.start.book.name !== section.end.book.name) {
ref = ref.concat(' - ').concat(section.end.book.name).concat(' ');
} else {
ref = ref.concat(' - ');
}
ref = ref.concat(' - ');
ref = ref.concat(section.end.chapter).concat(':');
@ -1943,8 +1931,7 @@ export class BibleReference {
const parts = this.ref.split(':');
if (parts.length === 3 && parts.every((i) => parseInt(i, 10) > 0)) {
const fbook = BibleReference.bookName(parseInt(parts[0], 10));
this.Section.end.book = fbook;
this.Section.start.book = fbook;
this.Section.book = fbook;
const fch = parts[1];
this.Section.end.chapter = fch;
@ -1966,11 +1953,7 @@ export class BibleReference {
fbook = this.ref;
}
this.ref = this.ref.slice(this.ref.search(/\w\s+\d/i) + 1);
if (isEnd) {
this.Section.end.book = BibleReference.parseBook(fbook);
} else {
this.Section.start.book = BibleReference.parseBook(fbook);
}
this.Section.book = BibleReference.parseBook(fbook);
}
private parseFirstNum(isEnd: boolean) {
@ -2037,9 +2020,7 @@ export class BibleReference {
private maybeParseBook(isEnd: boolean) {
return this.maybeDo(() => {
if (this.ref.search(/\w\s+\d/i) === -1) {
this.Section.end.book = this.Section.start.book;
} else {
if (this.ref.search(/\w\s+\d/i) !== -1) {
this.parseBook(isEnd);
}
});
@ -2058,16 +2039,10 @@ export class BibleReference {
) {
const self = this;
return this.maybeDo(() => {
if (self.Section.end.book.name === self.Section.start.book.name) {
if (
self.ref.search(/:/) !== -1 ||
foundSecondBook ||
!foundFirstVerse
) {
self.parseFirstNum(isEnd);
}
self.parseSecondNum(true, isEnd);
if (self.ref.search(/:/) !== -1 || foundSecondBook || !foundFirstVerse) {
self.parseFirstNum(isEnd);
}
self.parseSecondNum(true, isEnd);
});
}
@ -2104,12 +2079,12 @@ export interface Book {
}
export interface Section {
book: Book;
start: Location;
end: Location;
}
export interface Location {
book: Book;
chapter: string;
verse: string;
}

View File

@ -705,7 +705,7 @@ export class AppService extends createStateService(reducer, initialState) {
const result = await this.getPassageFromApi(ref.Section);
return {
qry: ref.toString(),
dict: ref.Section.start.book.bookNumber > 39 ? 'G' : 'H',
dict: ref.Section.book.bookNumber > 39 ? 'G' : 'H',
type: 'Passage',
data: result,
};
@ -720,16 +720,16 @@ export class AppService extends createStateService(reducer, initialState) {
ref: BibleReference.toString(section),
};
if (Number(section.start.chapter) > section.start.book.lastChapter) {
if (Number(section.start.chapter) > section.book.lastChapter) {
this.dispatchError(
`The requested chapter ${section.start.book.name} is out of range. Please pick a chapter between 1 and ${section.end.book.lastChapter}.`
`The requested chapter ${section.book.name} is out of range. Please pick a chapter between 1 and ${section.book.lastChapter}.`
);
return;
}
if (Number(section.end.chapter) > section.end.book.lastChapter) {
if (Number(section.end.chapter) > section.book.lastChapter) {
this.dispatchError(
`The requested chapter ${section.end.book.name} is out of range. Please pick a chapter between 1 and ${section.end.book.lastChapter}.`
`The requested chapter ${section.book.name} is out of range. Please pick a chapter between 1 and ${section.book.lastChapter}.`
);
return;
}
@ -742,7 +742,7 @@ export class AppService extends createStateService(reducer, initialState) {
try {
const d = await this.http
.get<BiblePassage>(
`${this.dataPath}/bibles/kjv_strongs/${section.start.book.bookNumber}-${i}.json`
`${this.dataPath}/bibles/kjv_strongs/${section.book.bookNumber}-${i}.json`
)
.toPromise();
chapters.push(d);
@ -804,7 +804,7 @@ export class AppService extends createStateService(reducer, initialState) {
// convert into paragraphs.
result.cs = await this.convertToParagraphPassages(passages, section);
if (section.start.book.bookNumber >= 40) {
if (section.book.bookNumber >= 40) {
result.testament = 'new';
} else {
result.testament = 'old';
@ -879,7 +879,7 @@ export class AppService extends createStateService(reducer, initialState) {
private getRefKey(vs: BibleVerse, section: Section) {
return BibleReference.formatReferenceKey(
section.start.book.bookNumber,
section.book.bookNumber,
section.start.chapter,
vs.v
);