pericope 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pericope.rb +42 -22
- data/lib/pericope/version.rb +1 -1
- metadata +18 -2
data/lib/pericope.rb
CHANGED
@@ -229,6 +229,10 @@ class Pericope
|
|
229
229
|
chapter_verse_counts[id]
|
230
230
|
end
|
231
231
|
|
232
|
+
def self.get_max_chapter(book)
|
233
|
+
book_chapter_counts[book - 1]
|
234
|
+
end
|
235
|
+
|
232
236
|
|
233
237
|
|
234
238
|
private
|
@@ -277,24 +281,30 @@ private
|
|
277
281
|
get_id(book, chapter, verse)
|
278
282
|
end
|
279
283
|
|
280
|
-
def self.
|
281
|
-
book
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
284
|
+
def self.to_valid_book(book)
|
285
|
+
coerce_to_range(book, 1..66)
|
286
|
+
end
|
287
|
+
|
288
|
+
def self.to_valid_chapter(book, chapter)
|
289
|
+
coerce_to_range(chapter, 1..get_max_chapter(book))
|
290
|
+
end
|
291
|
+
|
292
|
+
def self.to_valid_verse(book, chapter, verse)
|
293
|
+
coerce_to_range(verse, 1..get_max_verse(book, chapter))
|
294
|
+
end
|
295
|
+
|
296
|
+
def self.coerce_to_range(number, range)
|
297
|
+
return range.begin if number < range.begin
|
298
|
+
return range.end if number > range.end
|
299
|
+
number
|
300
|
+
end
|
301
|
+
|
302
|
+
def self.get_id(book, chapter, verse)
|
303
|
+
book = to_valid_book(book)
|
304
|
+
chapter = to_valid_chapter(book, chapter)
|
305
|
+
verse = to_valid_verse(book, chapter, verse)
|
296
306
|
|
297
|
-
|
307
|
+
(book * 1000000) + (chapter * 1000) + verse
|
298
308
|
end
|
299
309
|
|
300
310
|
def self.get_book(id)
|
@@ -383,32 +393,42 @@ private
|
|
383
393
|
ranges.map do |range|
|
384
394
|
range = range.split('-') # parse the low end of a verse range and the high end separately
|
385
395
|
range << range[0] if (range.length < 2) # treat 12:4 as 12:4-12:4
|
386
|
-
lower_chapter_verse = range[0].split(':').map
|
387
|
-
upper_chapter_verse = range[1].split(':').map
|
396
|
+
lower_chapter_verse = range[0].split(':').map(&:to_i) # parse "3:28" to [3,28]
|
397
|
+
upper_chapter_verse = range[1].split(':').map(&:to_i) # parse "3:28" to [3,28]
|
388
398
|
|
389
399
|
# make sure the low end of the range and the high end of the range
|
390
400
|
# are composed of arrays with two appropriate values: [chapter, verse]
|
391
401
|
chapter_range = false
|
392
402
|
if lower_chapter_verse.length < 2
|
393
|
-
if recent_chapter
|
403
|
+
if recent_chapter
|
394
404
|
lower_chapter_verse.unshift recent_chapter # e.g. parsing 11 in 12:1-8,11 => remember that 12 is the chapter
|
395
405
|
else
|
406
|
+
lower_chapter_verse[0] = Pericope.to_valid_chapter(book, lower_chapter_verse[0])
|
396
407
|
lower_chapter_verse << 1 # no verse specified; this is a range of chapters, start with verse 1
|
397
408
|
chapter_range = true
|
398
409
|
end
|
410
|
+
else
|
411
|
+
lower_chapter_verse[0] = Pericope.to_valid_chapter(book, lower_chapter_verse[0])
|
399
412
|
end
|
413
|
+
lower_chapter_verse[1] = Pericope.to_valid_verse(book, *lower_chapter_verse)
|
414
|
+
|
400
415
|
if upper_chapter_verse.length < 2
|
401
416
|
if chapter_range
|
417
|
+
upper_chapter_verse[0] = Pericope.to_valid_chapter(book, upper_chapter_verse[0])
|
402
418
|
upper_chapter_verse << Pericope.get_max_verse(book, upper_chapter_verse[0]) # this is a range of chapters, end with the last verse
|
403
419
|
else
|
404
420
|
upper_chapter_verse.unshift lower_chapter_verse[0] # e.g. parsing 8 in 12:1-8 => remember that 12 is the chapter
|
405
421
|
end
|
422
|
+
else
|
423
|
+
upper_chapter_verse[0] = Pericope.to_valid_chapter(book, upper_chapter_verse[0])
|
406
424
|
end
|
425
|
+
upper_chapter_verse[1] = Pericope.to_valid_verse(book, *upper_chapter_verse)
|
426
|
+
|
407
427
|
recent_chapter = upper_chapter_verse[0] # remember the last chapter
|
408
428
|
|
409
429
|
Range.new(
|
410
|
-
Pericope.get_id(book, lower_chapter_verse
|
411
|
-
Pericope.get_id(book, upper_chapter_verse
|
430
|
+
Pericope.get_id(book, *lower_chapter_verse),
|
431
|
+
Pericope.get_id(book, *upper_chapter_verse))
|
412
432
|
end
|
413
433
|
end
|
414
434
|
|
data/lib/pericope/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pericope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description:
|
47
63
|
email:
|
48
64
|
- bob.lailfamily@gmail.com
|