mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-23 23:39:50 -04:00
move book one level up in reference
This commit is contained in:
parent
26ad51c57f
commit
cdb54947cb
@ -20,13 +20,12 @@ class StringUtils {
|
|||||||
export class BibleReference {
|
export class BibleReference {
|
||||||
constructor(reference: string) {
|
constructor(reference: string) {
|
||||||
this.Section = {
|
this.Section = {
|
||||||
|
book: null,
|
||||||
start: {
|
start: {
|
||||||
book: null,
|
|
||||||
chapter: '',
|
chapter: '',
|
||||||
verse: '',
|
verse: '',
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
book: null,
|
|
||||||
chapter: '',
|
chapter: '',
|
||||||
verse: '',
|
verse: '',
|
||||||
},
|
},
|
||||||
@ -34,17 +33,12 @@ export class BibleReference {
|
|||||||
this.ref = reference.toLowerCase().trim();
|
this.ref = reference.toLowerCase().trim();
|
||||||
this.parseReference();
|
this.parseReference();
|
||||||
|
|
||||||
if (this.Section.end.book === null) {
|
|
||||||
this.Section.end.book = this.Section.start.book;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.Section.end.chapter === '') {
|
if (this.Section.end.chapter === '') {
|
||||||
this.Section.end.chapter = this.Section.start.chapter;
|
this.Section.end.chapter = this.Section.start.chapter;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
Number(this.Section.start.verse) > Number(this.Section.end.verse) &&
|
Number(this.Section.start.verse) > Number(this.Section.end.verse) &&
|
||||||
this.Section.start.chapter === this.Section.end.chapter &&
|
this.Section.start.chapter === this.Section.end.chapter
|
||||||
this.Section.start.book.name === this.Section.end.book.name
|
|
||||||
) {
|
) {
|
||||||
this.Section.end.verse = this.Section.start.verse;
|
this.Section.end.verse = this.Section.start.verse;
|
||||||
}
|
}
|
||||||
@ -1870,7 +1864,7 @@ export class BibleReference {
|
|||||||
|
|
||||||
public static toString(section: Section) {
|
public static toString(section: Section) {
|
||||||
// get the starting book, chapter, verse
|
// get the starting book, chapter, verse
|
||||||
let ref = section.start.book.name
|
let ref = section.book.name
|
||||||
.concat(' ')
|
.concat(' ')
|
||||||
.concat(section.start.chapter)
|
.concat(section.start.chapter)
|
||||||
.concat(':')
|
.concat(':')
|
||||||
@ -1878,25 +1872,19 @@ export class BibleReference {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
section.start.chapter === section.end.chapter &&
|
section.start.chapter === section.end.chapter &&
|
||||||
section.start.verse === section.end.verse &&
|
section.start.verse === section.end.verse
|
||||||
section.start.book.name === section.end.book.name
|
|
||||||
) {
|
) {
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
section.start.chapter === section.end.chapter &&
|
section.start.chapter === section.end.chapter &&
|
||||||
section.start.verse !== section.end.verse &&
|
section.start.verse !== section.end.verse
|
||||||
section.start.book.name === section.end.book.name
|
|
||||||
) {
|
) {
|
||||||
return ref.concat(' - ').concat(section.end.verse);
|
return ref.concat(' - ').concat(section.end.verse);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section.start.book.name !== section.end.book.name) {
|
ref = ref.concat(' - ');
|
||||||
ref = ref.concat(' - ').concat(section.end.book.name).concat(' ');
|
|
||||||
} else {
|
|
||||||
ref = ref.concat(' - ');
|
|
||||||
}
|
|
||||||
|
|
||||||
ref = ref.concat(section.end.chapter).concat(':');
|
ref = ref.concat(section.end.chapter).concat(':');
|
||||||
|
|
||||||
@ -1943,8 +1931,7 @@ export class BibleReference {
|
|||||||
const parts = this.ref.split(':');
|
const parts = this.ref.split(':');
|
||||||
if (parts.length === 3 && parts.every((i) => parseInt(i, 10) > 0)) {
|
if (parts.length === 3 && parts.every((i) => parseInt(i, 10) > 0)) {
|
||||||
const fbook = BibleReference.bookName(parseInt(parts[0], 10));
|
const fbook = BibleReference.bookName(parseInt(parts[0], 10));
|
||||||
this.Section.end.book = fbook;
|
this.Section.book = fbook;
|
||||||
this.Section.start.book = fbook;
|
|
||||||
|
|
||||||
const fch = parts[1];
|
const fch = parts[1];
|
||||||
this.Section.end.chapter = fch;
|
this.Section.end.chapter = fch;
|
||||||
@ -1966,11 +1953,7 @@ export class BibleReference {
|
|||||||
fbook = this.ref;
|
fbook = this.ref;
|
||||||
}
|
}
|
||||||
this.ref = this.ref.slice(this.ref.search(/\w\s+\d/i) + 1);
|
this.ref = this.ref.slice(this.ref.search(/\w\s+\d/i) + 1);
|
||||||
if (isEnd) {
|
this.Section.book = BibleReference.parseBook(fbook);
|
||||||
this.Section.end.book = BibleReference.parseBook(fbook);
|
|
||||||
} else {
|
|
||||||
this.Section.start.book = BibleReference.parseBook(fbook);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseFirstNum(isEnd: boolean) {
|
private parseFirstNum(isEnd: boolean) {
|
||||||
@ -2037,9 +2020,7 @@ export class BibleReference {
|
|||||||
|
|
||||||
private maybeParseBook(isEnd: boolean) {
|
private maybeParseBook(isEnd: boolean) {
|
||||||
return this.maybeDo(() => {
|
return this.maybeDo(() => {
|
||||||
if (this.ref.search(/\w\s+\d/i) === -1) {
|
if (this.ref.search(/\w\s+\d/i) !== -1) {
|
||||||
this.Section.end.book = this.Section.start.book;
|
|
||||||
} else {
|
|
||||||
this.parseBook(isEnd);
|
this.parseBook(isEnd);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -2058,16 +2039,10 @@ export class BibleReference {
|
|||||||
) {
|
) {
|
||||||
const self = this;
|
const self = this;
|
||||||
return this.maybeDo(() => {
|
return this.maybeDo(() => {
|
||||||
if (self.Section.end.book.name === self.Section.start.book.name) {
|
if (self.ref.search(/:/) !== -1 || foundSecondBook || !foundFirstVerse) {
|
||||||
if (
|
self.parseFirstNum(isEnd);
|
||||||
self.ref.search(/:/) !== -1 ||
|
|
||||||
foundSecondBook ||
|
|
||||||
!foundFirstVerse
|
|
||||||
) {
|
|
||||||
self.parseFirstNum(isEnd);
|
|
||||||
}
|
|
||||||
self.parseSecondNum(true, isEnd);
|
|
||||||
}
|
}
|
||||||
|
self.parseSecondNum(true, isEnd);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2104,12 +2079,12 @@ export interface Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Section {
|
export interface Section {
|
||||||
|
book: Book;
|
||||||
start: Location;
|
start: Location;
|
||||||
end: Location;
|
end: Location;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Location {
|
export interface Location {
|
||||||
book: Book;
|
|
||||||
chapter: string;
|
chapter: string;
|
||||||
verse: string;
|
verse: string;
|
||||||
}
|
}
|
||||||
|
@ -705,7 +705,7 @@ export class AppService extends createStateService(reducer, initialState) {
|
|||||||
const result = await this.getPassageFromApi(ref.Section);
|
const result = await this.getPassageFromApi(ref.Section);
|
||||||
return {
|
return {
|
||||||
qry: ref.toString(),
|
qry: ref.toString(),
|
||||||
dict: ref.Section.start.book.bookNumber > 39 ? 'G' : 'H',
|
dict: ref.Section.book.bookNumber > 39 ? 'G' : 'H',
|
||||||
type: 'Passage',
|
type: 'Passage',
|
||||||
data: result,
|
data: result,
|
||||||
};
|
};
|
||||||
@ -720,16 +720,16 @@ export class AppService extends createStateService(reducer, initialState) {
|
|||||||
ref: BibleReference.toString(section),
|
ref: BibleReference.toString(section),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Number(section.start.chapter) > section.start.book.lastChapter) {
|
if (Number(section.start.chapter) > section.book.lastChapter) {
|
||||||
this.dispatchError(
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number(section.end.chapter) > section.end.book.lastChapter) {
|
if (Number(section.end.chapter) > section.book.lastChapter) {
|
||||||
this.dispatchError(
|
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;
|
return;
|
||||||
}
|
}
|
||||||
@ -742,7 +742,7 @@ export class AppService extends createStateService(reducer, initialState) {
|
|||||||
try {
|
try {
|
||||||
const d = await this.http
|
const d = await this.http
|
||||||
.get<BiblePassage>(
|
.get<BiblePassage>(
|
||||||
`${this.dataPath}/bibles/kjv_strongs/${section.start.book.bookNumber}-${i}.json`
|
`${this.dataPath}/bibles/kjv_strongs/${section.book.bookNumber}-${i}.json`
|
||||||
)
|
)
|
||||||
.toPromise();
|
.toPromise();
|
||||||
chapters.push(d);
|
chapters.push(d);
|
||||||
@ -804,7 +804,7 @@ export class AppService extends createStateService(reducer, initialState) {
|
|||||||
// convert into paragraphs.
|
// convert into paragraphs.
|
||||||
result.cs = await this.convertToParagraphPassages(passages, section);
|
result.cs = await this.convertToParagraphPassages(passages, section);
|
||||||
|
|
||||||
if (section.start.book.bookNumber >= 40) {
|
if (section.book.bookNumber >= 40) {
|
||||||
result.testament = 'new';
|
result.testament = 'new';
|
||||||
} else {
|
} else {
|
||||||
result.testament = 'old';
|
result.testament = 'old';
|
||||||
@ -879,7 +879,7 @@ export class AppService extends createStateService(reducer, initialState) {
|
|||||||
|
|
||||||
private getRefKey(vs: BibleVerse, section: Section) {
|
private getRefKey(vs: BibleVerse, section: Section) {
|
||||||
return BibleReference.formatReferenceKey(
|
return BibleReference.formatReferenceKey(
|
||||||
section.start.book.bookNumber,
|
section.book.bookNumber,
|
||||||
section.start.chapter,
|
section.start.chapter,
|
||||||
vs.v
|
vs.v
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user