bible_ref 1.4.0 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- 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 +7 -0
- data/lib/bible_ref/languages/romanian.rb +7 -0
- data/lib/bible_ref/reference.rb +16 -21
- data/lib/bible_ref/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfd107c033d80842c4439b6b1b051494c2159b9a09ff8b37f8619dddc7047c05
|
4
|
+
data.tar.gz: 6c89efe81988afabc86f8cc59dabc9761b902a25cf87d2666f3d1325ff18780c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a2606c594f7b74000a47c109155f5db6dd91a0d584d350daf0b6747ec4dbdc201d553cc9765d62d2323d20d351037ab43dae6f20af5952199464d9bc05203f6
|
7
|
+
data.tar.gz: 4cdd24de24e1cd85edcd726917afa60fabc317b5dd0c9757a00b9b257f16a40ea4698d3e8cc4db3869f2e8172a0d5f9534f36178f890e524f2be86dd0f951861
|
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.
|
@@ -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: /^(jth|jdth?|judith)/, name: 'Judith'
|
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' },
|
@@ -63,7 +69,7 @@ module BibleRef
|
|
63
69
|
'3MA' => { match: /^3 ?mac?/, name: '3 Maccabees' },
|
64
70
|
'2ES' => { match: /^2 ?esd?/, name: '2 Esdras' },
|
65
71
|
'4MA' => { match: /^4 ?mac?/, name: '4 Maccabees' },
|
66
|
-
'MAT' => { match: /^
|
72
|
+
'MAT' => { match: /^ma?t/, name: 'Matthew' },
|
67
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' },
|
@@ -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' },
|
@@ -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' },
|
data/lib/bible_ref/reference.rb
CHANGED
@@ -8,10 +8,11 @@ module BibleRef
|
|
8
8
|
|
9
9
|
# Create a new Reference instance by passing in the user-supplied bible reference as a string.
|
10
10
|
def initialize(reference, language: 'eng', canon: 'all')
|
11
|
-
@reference = reference
|
12
|
-
@details = parse
|
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.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Morgan
|
8
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
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.2.22
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Bible reference parser
|