bible_ref 1.2.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/bible_ref/canons/all.rb +15 -0
- data/lib/bible_ref/canons.rb +3 -2
- data/lib/bible_ref/languages/base.rb +5 -0
- data/lib/bible_ref/languages/cherokee.rb +7 -0
- data/lib/bible_ref/languages/english.rb +11 -5
- data/lib/bible_ref/languages/latin.rb +6 -0
- data/lib/bible_ref/languages/portuguese.rb +8 -1
- data/lib/bible_ref/languages/romanian.rb +8 -1
- data/lib/bible_ref/reference.rb +17 -22
- data/lib/bible_ref/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ff84390f97873c222f3b4f3de5cc4eddecf4248e96fd4969dfcee397989687f
|
4
|
+
data.tar.gz: 27188298c69c82dc025d680c2725b71d3169e90aca47d64ad94322221aa01121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e30d34f9878276275e136e974b114ecf2365e21be79821d3513a278e9094fa134a2ef80743dc07a1daa572b9c48f402a13def18966abf54bdfb902523a4697df
|
7
|
+
data.tar.gz: 4e2bf7bfe56773162e8618d7f189284b283b3c15e4b0b56092390a0df4b6c5accf5efe8ee6272aa136d5766198aee98c5943a1c8d1df792780a7964e5ef7816c
|
data/README.md
CHANGED
@@ -53,6 +53,11 @@ verses = ranges.map do |from_ref, to_ref|
|
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
56
|
+
## Note
|
57
|
+
|
58
|
+
When searching a book that contains a single chapter (ie. Obadiah, Philemon, Jude, 2 John, 3 John), you can use either Jude 1 or Jude 1:1 to retrieve verse 1.
|
59
|
+
This is quite different from searching a book with multiple chapters. **John 1** will return all of chapter 1, where as **Jude 1** only returns the first verse.
|
60
|
+
|
56
61
|
## Copyright
|
57
62
|
|
58
63
|
Copyright [Tim Morgan](http://timmorgan.org). Licensed MIT.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BibleRef
|
2
|
+
module Canons
|
3
|
+
class All
|
4
|
+
def books
|
5
|
+
%w(
|
6
|
+
GEN EXO LEV NUM DEU JOS JDG RUT 1SA 2SA 1KI 2KI 1CH 2CH EZR NEH EST JOB
|
7
|
+
PSA PRO ECC SNG ISA JER LAM EZK DAN HOS JOL AMO OBA JON MIC NAM HAB ZEP HAG
|
8
|
+
ZEC MAL TOB JDT ESG WIS SIR BAR LJE S3Y SUS BEL 1MA 2MA 1ES MAN PS2 3MA 2ES
|
9
|
+
4MA MAT MRK LUK JHN ACT ROM 1CO 2CO GAL EPH PHP COL 1TH 2TH 1TI 2TI TIT PHM
|
10
|
+
HEB JAS 1PE 2PE 1JN 2JN 3JN JUD REV
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/bible_ref/canons.rb
CHANGED
@@ -5,6 +5,11 @@ module BibleRef
|
|
5
5
|
fail NotImplementedError, "You must override #books in your language class."
|
6
6
|
end
|
7
7
|
|
8
|
+
# Is it a single chapter book?
|
9
|
+
def has_single_chapter?(reference)
|
10
|
+
fail NotImplementedError, "You must override #has_single_chapter? in your language class."
|
11
|
+
end
|
12
|
+
|
8
13
|
def book_id(book_name, canon)
|
9
14
|
book_name = replace_roman_numerals(book_name)
|
10
15
|
return book_name.upcase if books[book_name.upcase] # already normalized
|
@@ -4,6 +4,13 @@ require_relative 'base'
|
|
4
4
|
module BibleRef
|
5
5
|
module Languages
|
6
6
|
class Cherokee < Base
|
7
|
+
|
8
|
+
# Is it a single chapter book?
|
9
|
+
def has_single_chapter?(reference)
|
10
|
+
matches = ['ᏉᎳ ᏆᎵᎹᏂ ᎤᏬᏪᎳᏁᎸᎯ', 'ᏣᏂ ᏔᎵᏁ ᎤᏬᏪᎳᏅᎯ', 'ᏣᏂ ᏦᎢᏁ ᎤᏬᏪᎳᏅᎯ', 'ᏧᏓᏏ ᎤᏬᏪᎳᏅᎯ']
|
11
|
+
return matches.any? { |e| reference.include?(e) }
|
12
|
+
end
|
13
|
+
|
7
14
|
def books
|
8
15
|
{
|
9
16
|
'MAT' => { name: 'ᎣᏍᏛ ᎧᏃᎮᏛ ᎹᏚ ᎤᏬᏪᎳᏅᎯ' },
|
@@ -4,6 +4,12 @@ require_relative 'base'
|
|
4
4
|
module BibleRef
|
5
5
|
module Languages
|
6
6
|
class English < Base
|
7
|
+
# Is it a single chapter book?
|
8
|
+
def has_single_chapter?(reference)
|
9
|
+
matches = [/^ob/, /^(jud|jd|jude)\b/, /^2 ?jo?h?n/, /^3 ?jo?h?n/, /^(philem|phm|pm)/]
|
10
|
+
return Regexp.union(matches).match?(reference.downcase)
|
11
|
+
end
|
12
|
+
|
7
13
|
def books
|
8
14
|
{
|
9
15
|
'GEN' => { match: /^gen/, name: 'Genesis' },
|
@@ -46,7 +52,7 @@ module BibleRef
|
|
46
52
|
'ZEC' => { match: /^zec/, name: 'Zechariah' },
|
47
53
|
'MAL' => { match: /^mal/, name: 'Malachi' },
|
48
54
|
'TOB' => { match: /^tob/, name: 'Tobit' },
|
49
|
-
'JDT' => { match: /^(
|
55
|
+
'JDT' => { match: /^(jth|jdth?|judith)/, name: 'Judith' },
|
50
56
|
'ESG' => { match: /^(est.*greek|esg)/, name: 'Esther (Greek)' },
|
51
57
|
'WIS' => { match: /^wis(dom)?/, name: 'Wisdom of Solomon' },
|
52
58
|
'SIR' => { match: /^sir/, name: 'Sirach' },
|
@@ -64,7 +70,7 @@ module BibleRef
|
|
64
70
|
'2ES' => { match: /^2 ?esd?/, name: '2 Esdras' },
|
65
71
|
'4MA' => { match: /^4 ?mac?/, name: '4 Maccabees' },
|
66
72
|
'MAT' => { match: /^mat/, name: 'Matthew' },
|
67
|
-
'MRK' => { match: /^ma?rk/,
|
73
|
+
'MRK' => { match: /^(ma?rk|mk)/, name: 'Mark' },
|
68
74
|
'LUK' => { match: /^lu?k/, name: 'Luke' },
|
69
75
|
'JHN' => { match: /^(john|jn|jhn)/, name: 'John' },
|
70
76
|
'ACT' => { match: /^act/, name: 'Acts' },
|
@@ -73,14 +79,14 @@ module BibleRef
|
|
73
79
|
'2CO' => { match: /^2 ?cor?/, name: '2 Corinthians' },
|
74
80
|
'GAL' => { match: /^gal/, name: 'Galatians' },
|
75
81
|
'EPH' => { match: /^eph/, name: 'Ephesians' },
|
76
|
-
'PHP' => { match: /^(
|
82
|
+
'PHP' => { match: /^(phil|php|pp)/, name: 'Philippians' },
|
77
83
|
'COL' => { match: /^col/, name: 'Colossians' },
|
78
84
|
'1TH' => { match: /^1 ?the?s?/, name: '1 Thessalonians' },
|
79
85
|
'2TH' => { match: /^2 ?the?s?/, name: '2 Thessalonians' },
|
80
86
|
'1TI' => { match: /^1 ?tim?/, name: '1 Timothy' },
|
81
87
|
'2TI' => { match: /^2 ?tim?/, name: '2 Timothy' },
|
82
88
|
'TIT' => { match: /^tit/, name: 'Titus' },
|
83
|
-
'PHM' => { match: /^
|
89
|
+
'PHM' => { match: /^(philem|phm|pm)/, name: 'Philemon' },
|
84
90
|
'HEB' => { match: /^heb/, name: 'Hebrews' },
|
85
91
|
'JAS' => { match: /^ja(m|s)/, name: 'James' },
|
86
92
|
'1PE' => { match: /^1 ?pet?/, name: '1 Peter' },
|
@@ -88,7 +94,7 @@ module BibleRef
|
|
88
94
|
'1JN' => { match: /^1 ?jo?h?n/, name: '1 John' },
|
89
95
|
'2JN' => { match: /^2 ?jo?h?n/, name: '2 John' },
|
90
96
|
'3JN' => { match: /^3 ?jo?h?n/, name: '3 John' },
|
91
|
-
'JUD' => { match: /^jud
|
97
|
+
'JUD' => { match: /^(jud|jd|jude)$/, name: 'Jude' },
|
92
98
|
'REV' => { match: /^re?v/, name: 'Revelation' }
|
93
99
|
}
|
94
100
|
end
|
@@ -4,6 +4,12 @@ require_relative 'base'
|
|
4
4
|
module BibleRef
|
5
5
|
module Languages
|
6
6
|
class Latin < Base
|
7
|
+
# Is it a single chapter book?
|
8
|
+
def has_single_chapter?(reference)
|
9
|
+
matches = ['Abdias', 'ad Philemonem', 'Joannis II', 'Joannis III', 'Judæ']
|
10
|
+
return matches.any? { |e| reference.include?(e) }
|
11
|
+
end
|
12
|
+
|
7
13
|
def books
|
8
14
|
{
|
9
15
|
'GEN' => { name: 'Genesis' },
|
@@ -4,6 +4,13 @@ require_relative 'base'
|
|
4
4
|
module BibleRef
|
5
5
|
module Languages
|
6
6
|
class Portuguese < Base
|
7
|
+
|
8
|
+
# Is it a single chapter book?
|
9
|
+
def has_single_chapter?(reference)
|
10
|
+
matches = [/^ob/, /^jud/, /^2 jo/, /^3 jo/, /^fil/]
|
11
|
+
return Regexp.union(matches).match?(reference.downcase)
|
12
|
+
end
|
13
|
+
|
7
14
|
def books
|
8
15
|
{
|
9
16
|
'GEN' => { match: /^g[eê]n/, name: 'Gênesis' },
|
@@ -46,7 +53,7 @@ module BibleRef
|
|
46
53
|
'ZEC' => { match: /^zac/, name: 'Zacarias' },
|
47
54
|
'MAL' => { match: /^mal/, name: 'Malaquias' },
|
48
55
|
'MAT' => { match: /^mat/, name: 'Mateus' },
|
49
|
-
'MRK' => { match: /^mar/,
|
56
|
+
'MRK' => { match: /^(mar|mk)/, name: 'Marcos' },
|
50
57
|
'LUK' => { match: /^lu/, name: 'Lucas' },
|
51
58
|
'JHN' => { match: /^jo/, name: 'João' },
|
52
59
|
'ACT' => { match: /^at/, name: 'Atos' },
|
@@ -4,6 +4,13 @@ require_relative 'base'
|
|
4
4
|
module BibleRef
|
5
5
|
module Languages
|
6
6
|
class Romanian < Base
|
7
|
+
|
8
|
+
# Is it a single chapter book?
|
9
|
+
def has_single_chapter?(reference)
|
10
|
+
matches = [/^ob/, /^iud/, /^2 io/, /^3 io/, /^fil/]
|
11
|
+
return Regexp.union(matches).match?(reference.downcase)
|
12
|
+
end
|
13
|
+
|
7
14
|
def books
|
8
15
|
{
|
9
16
|
'GEN' => { match: /^gen/, name: 'Geneza' },
|
@@ -46,7 +53,7 @@ module BibleRef
|
|
46
53
|
'ZEC' => { match: /^za/, name: 'Zaharia' },
|
47
54
|
'MAL' => { match: /^mal/, name: 'Maleahi' },
|
48
55
|
'MAT' => { match: /^mat/, name: 'Matei' },
|
49
|
-
'MRK' => { match: /^mar/,
|
56
|
+
'MRK' => { match: /^(mar|mk)/, name: 'Marcu' },
|
50
57
|
'LUK' => { match: /^lu/, name: 'Luca' },
|
51
58
|
'JHN' => { match: /^io/, name: 'Ioan' },
|
52
59
|
'ACT' => { match: /^fa/, name: 'Faptele apostolilor' },
|
data/lib/bible_ref/reference.rb
CHANGED
@@ -7,11 +7,12 @@ module BibleRef
|
|
7
7
|
attr_reader :book, :reference, :language, :canon
|
8
8
|
|
9
9
|
# Create a new Reference instance by passing in the user-supplied bible reference as a string.
|
10
|
-
def initialize(reference, language: 'eng', canon: '
|
11
|
-
@reference = reference
|
12
|
-
@details = parse
|
10
|
+
def initialize(reference, language: 'eng', canon: 'all')
|
13
11
|
@language = language.respond_to?(:book_id) ? language : LANGUAGES.fetch(language.to_s).new
|
14
12
|
@canon = canon.respond_to?(:books) ? canon : CANONS.fetch(canon.to_s).new
|
13
|
+
@reference = reference
|
14
|
+
standardize_reference()
|
15
|
+
@details = parse
|
15
16
|
end
|
16
17
|
|
17
18
|
# Returns an array of pairs, each one being the from and to for a range.
|
@@ -22,7 +23,6 @@ module BibleRef
|
|
22
23
|
def ranges
|
23
24
|
return nil unless valid?
|
24
25
|
@chapter = nil
|
25
|
-
fix_chapter_for_jude if book_id == 'JUD'
|
26
26
|
[@details[:refs]].flatten.map do |ref|
|
27
27
|
normalize_range(ref) || normalize_ref(ref)
|
28
28
|
end
|
@@ -75,6 +75,19 @@ module BibleRef
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
# standardize the reference so it can be handed to the parser.
|
79
|
+
def standardize_reference
|
80
|
+
return @reference unless @language.has_single_chapter?(@reference)
|
81
|
+
return @reference if @reference.include? ':'
|
82
|
+
|
83
|
+
matches = @reference.match(/^([\d]?[\D\s]*)/)
|
84
|
+
return @reference if matches.length() == 0
|
85
|
+
|
86
|
+
book = matches[0].strip
|
87
|
+
requested = @reference.sub(book, '').strip
|
88
|
+
@reference = "#{book} 1:#{requested}"
|
89
|
+
end
|
90
|
+
|
78
91
|
def parse
|
79
92
|
begin
|
80
93
|
parsed = Parser.new.parse(@reference)
|
@@ -102,23 +115,5 @@ module BibleRef
|
|
102
115
|
end
|
103
116
|
end
|
104
117
|
|
105
|
-
def fix_chapter_for_jude
|
106
|
-
(start, finish) = @details[:refs]
|
107
|
-
finish ||= start
|
108
|
-
@details[:refs] = [
|
109
|
-
{
|
110
|
-
range: {
|
111
|
-
from: {
|
112
|
-
chapter: 1,
|
113
|
-
verse: start[:chapter]
|
114
|
-
},
|
115
|
-
to: {
|
116
|
-
chapter: 1,
|
117
|
-
verse: finish[:chapter]
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
]
|
122
|
-
end
|
123
118
|
end
|
124
119
|
end
|
data/lib/bible_ref/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bible_ref
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Morgan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- README.md
|
63
63
|
- lib/bible_ref.rb
|
64
64
|
- lib/bible_ref/canons.rb
|
65
|
+
- lib/bible_ref/canons/all.rb
|
65
66
|
- lib/bible_ref/canons/protestant.rb
|
66
67
|
- lib/bible_ref/languages.rb
|
67
68
|
- lib/bible_ref/languages/base.rb
|
@@ -77,7 +78,7 @@ homepage: https://github.com/seven1m/bible_ref
|
|
77
78
|
licenses:
|
78
79
|
- MIT
|
79
80
|
metadata: {}
|
80
|
-
post_install_message:
|
81
|
+
post_install_message:
|
81
82
|
rdoc_options: []
|
82
83
|
require_paths:
|
83
84
|
- lib
|
@@ -92,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
- !ruby/object:Gem::Version
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
96
|
-
signing_key:
|
96
|
+
rubygems_version: 3.1.6
|
97
|
+
signing_key:
|
97
98
|
specification_version: 4
|
98
99
|
summary: Bible reference parser
|
99
100
|
test_files: []
|