bible_ref 0.1.0 → 0.2.0
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/lib/bible_ref/book.rb +91 -0
- data/lib/bible_ref/reference.rb +37 -5
- data/lib/bible_ref/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7620ceecdf8eb2efd2f77531477b879276732c3
|
4
|
+
data.tar.gz: e1f60d7af94a285df7f58dfb25eb408ddcfb1ab1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12ffede23ce5079666e1740fde4706ad43d67a5e776e700991a4d5ab423985c52e4953ffd4bf6cee578074736ce2a5ea30188d6ee0c94cc24580c72aa0b3be87
|
7
|
+
data.tar.gz: 96413110c682fccff792273c0e9fec29c8966ccf7b6d375e5cd348d1ac8524234dc8948fdce96d2685e27ab8f9a67efe8e5b8cb9b93b839ca001ff1fe2d1b60f
|
data/lib/bible_ref/book.rb
CHANGED
@@ -98,6 +98,93 @@ module BibleRef
|
|
98
98
|
'REV' => /^re?v/
|
99
99
|
}
|
100
100
|
|
101
|
+
FORMATTED_BOOKS = {
|
102
|
+
'GEN' => 'Genesis',
|
103
|
+
'EXO' => 'Exodus',
|
104
|
+
'LEV' => 'Leviticus',
|
105
|
+
'NUM' => 'Numbers',
|
106
|
+
'DEU' => 'Deuteronomy',
|
107
|
+
'JOS' => 'Joshua',
|
108
|
+
'JDG' => 'Judges',
|
109
|
+
'RUT' => 'Ruth',
|
110
|
+
'1SA' => '1 Samuel',
|
111
|
+
'2SA' => '2 Samuel',
|
112
|
+
'1KI' => '1 Kings',
|
113
|
+
'2KI' => '2 Kings',
|
114
|
+
'1CH' => '1 Chronicles',
|
115
|
+
'2CH' => '2 Chronicles',
|
116
|
+
'EZR' => 'Ezra',
|
117
|
+
'NEH' => 'Nehemiah',
|
118
|
+
'EST' => 'Esther',
|
119
|
+
'JOB' => 'Job',
|
120
|
+
'PSA' => 'Psalms',
|
121
|
+
'PRO' => 'Proverbs',
|
122
|
+
'ECC' => 'Ecclesiastes',
|
123
|
+
'SNG' => 'Song of Solomon',
|
124
|
+
'ISA' => 'Isaiah',
|
125
|
+
'JER' => 'Jeremiah',
|
126
|
+
'LAM' => 'Lamentations',
|
127
|
+
'EZK' => 'Ezekiel',
|
128
|
+
'DAN' => 'Daniel',
|
129
|
+
'HOS' => 'Hosea',
|
130
|
+
'JOL' => 'Joel',
|
131
|
+
'AMO' => 'Amos',
|
132
|
+
'OBA' => 'Obadiah',
|
133
|
+
'JON' => 'Jonah',
|
134
|
+
'MIC' => 'Micah',
|
135
|
+
'NAM' => 'Nahum',
|
136
|
+
'HAB' => 'Habakkuk',
|
137
|
+
'ZEP' => 'Zephaniah',
|
138
|
+
'HAG' => 'Haggai',
|
139
|
+
'ZEC' => 'Zechariah',
|
140
|
+
'MAL' => 'Malachi',
|
141
|
+
'TOB' => 'Tobit',
|
142
|
+
'JDT' => 'Judith',
|
143
|
+
'ESG' => 'Esther (Greek)',
|
144
|
+
'WIS' => 'Wisdom of Solomon',
|
145
|
+
'SIR' => 'Sirach',
|
146
|
+
'BAR' => 'Baruch',
|
147
|
+
'LJE' => 'Jeremy’s Letter',
|
148
|
+
'S3Y' => '3 Holy Children’s Song',
|
149
|
+
'SUS' => 'Susanna',
|
150
|
+
'BEL' => 'Bel and the Dragon',
|
151
|
+
'1MA' => '1 Maccabees',
|
152
|
+
'2MA' => '2 Maccabees',
|
153
|
+
'1ES' => '1 Esdras',
|
154
|
+
'MAN' => 'Prayer of Manasses',
|
155
|
+
'PS2' => 'Psalm 151',
|
156
|
+
'3MA' => '3 Maccabees',
|
157
|
+
'2ES' => '2 Esdras',
|
158
|
+
'4MA' => '4 Maccabees',
|
159
|
+
'MAT' => 'Matthew',
|
160
|
+
'MRK' => 'Mark',
|
161
|
+
'LUK' => 'Luke',
|
162
|
+
'JHN' => 'John',
|
163
|
+
'ACT' => 'Acts',
|
164
|
+
'ROM' => 'Romans',
|
165
|
+
'1CO' => '1 Corinthians',
|
166
|
+
'2CO' => '2 Corinthians',
|
167
|
+
'GAL' => 'Galatians',
|
168
|
+
'EPH' => 'Ephesians',
|
169
|
+
'PHP' => 'Philippians',
|
170
|
+
'COL' => 'Colossians',
|
171
|
+
'1TH' => '1 Thessalonians',
|
172
|
+
'2TH' => '2 Thessalonians',
|
173
|
+
'1TI' => '1 Timothy',
|
174
|
+
'2TI' => '2 Timothy',
|
175
|
+
'TIT' => 'Titus',
|
176
|
+
'PHM' => 'Philemon',
|
177
|
+
'HEB' => 'Hebrews',
|
178
|
+
'JAS' => 'James',
|
179
|
+
'1PE' => '1 Peter',
|
180
|
+
'2PE' => '2 Peter',
|
181
|
+
'1JN' => '1 John',
|
182
|
+
'2JN' => '2 John',
|
183
|
+
'3JN' => '3 John',
|
184
|
+
'JUD' => 'Jude',
|
185
|
+
'REV' => 'Revelation'
|
186
|
+
}
|
187
|
+
|
101
188
|
def initialize(book, canon=:protestant)
|
102
189
|
@canon = canon
|
103
190
|
unless CANONS[@canon]
|
@@ -114,5 +201,9 @@ module BibleRef
|
|
114
201
|
nil
|
115
202
|
end
|
116
203
|
|
204
|
+
def formatted
|
205
|
+
FORMATTED_BOOKS[id]
|
206
|
+
end
|
207
|
+
|
117
208
|
end
|
118
209
|
end
|
data/lib/bible_ref/reference.rb
CHANGED
@@ -7,11 +7,17 @@ module BibleRef
|
|
7
7
|
attr_reader :book
|
8
8
|
attr_reader :reference
|
9
9
|
|
10
|
+
# Create a new Reference instance by passing in the user-supplied bible reference as a string.
|
10
11
|
def initialize(reference)
|
11
12
|
@reference = reference
|
12
13
|
@details = parse
|
13
14
|
end
|
14
15
|
|
16
|
+
# Returns an array of pairs, each one being the from and to for a range.
|
17
|
+
# For single verses, the same ref is repeated twice. This is most helpful
|
18
|
+
# for converting the entire passage into a SQL query, and in fact is exactly
|
19
|
+
# why this library was built. See https://github.com/seven1m/bible_api/blob/master/app.rb
|
20
|
+
# for an example.
|
15
21
|
def ranges
|
16
22
|
return nil unless valid?
|
17
23
|
@chapter = nil
|
@@ -20,16 +26,42 @@ module BibleRef
|
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
29
|
+
# Returns a BibleRef::Book instance or nil if book not known.
|
23
30
|
def book
|
24
|
-
|
31
|
+
return nil unless @details
|
32
|
+
@book ||= Book.new(@details[:book])
|
25
33
|
end
|
26
34
|
|
35
|
+
# Returns true if the reference is a known bible passage.
|
27
36
|
def valid?
|
28
|
-
@details and book
|
37
|
+
@details and book.id
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns a normalized passage reference. e.g.
|
41
|
+
#
|
42
|
+
# 'JOHN 3:16&17' => 'John 3:16,17'
|
43
|
+
def normalize
|
44
|
+
book.formatted + ' ' +
|
45
|
+
ranges.map do |(ref_from, ref_to)|
|
46
|
+
if ref_from != ref_to
|
47
|
+
ref_part(ref_from) + '-' + ref_part(ref_to)
|
48
|
+
else
|
49
|
+
ref_part(ref_from)
|
50
|
+
end
|
51
|
+
end.join(',')
|
29
52
|
end
|
30
53
|
|
31
54
|
private
|
32
55
|
|
56
|
+
def ref_part(ref)
|
57
|
+
if @last_chapter != ref[:chapter] and ref[:chapter]
|
58
|
+
@last_chapter = ref[:chapter]
|
59
|
+
"#{ref[:chapter]}:#{ref[:verse]}"
|
60
|
+
else
|
61
|
+
ref[:verse].to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
33
65
|
def parse
|
34
66
|
begin
|
35
67
|
parsed = Parser.new.parse(@reference)
|
@@ -45,15 +77,15 @@ module BibleRef
|
|
45
77
|
ch = range.detect { |_, r| r[:chapter] }
|
46
78
|
@chapter = ch.last[:chapter] if ch
|
47
79
|
[
|
48
|
-
{ book: @book, chapter: @chapter }.merge(range[:from]),
|
49
|
-
{ book: @book, chapter: @chapter }.merge(range[:to])
|
80
|
+
{ book: @book.id, chapter: @chapter }.merge(range[:from]),
|
81
|
+
{ book: @book.id, chapter: @chapter }.merge(range[:to])
|
50
82
|
]
|
51
83
|
end
|
52
84
|
|
53
85
|
def normalize_ref(ref)
|
54
86
|
@chapter = ref[:chapter] if ref[:chapter]
|
55
87
|
(1..2).map do
|
56
|
-
{ book: @book, chapter: @chapter }.merge(ref)
|
88
|
+
{ book: @book.id, chapter: @chapter }.merge(ref)
|
57
89
|
end
|
58
90
|
end
|
59
91
|
|
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: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|