bible_ref 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -3
- data/lib/bible_ref/reference.rb +15 -10
- data/lib/bible_ref/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f9a5343547b1777a07bb2876bf17b38e31225c1948571a85588758a8f3d915
|
4
|
+
data.tar.gz: 8d1d69e4b6b97bdb6d675ec1584b6abb45b5c2a7b2731ea7647443f7bc5c0138
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc93394a58615d9f47562e8d30e65c45aa3407b050574ef777994d0ff0775cd5aa7c44996538e56499f8006573ccce9341cc42e162935933ec248d2cb794f76a
|
7
|
+
data.tar.gz: c84fc9f49b17114c55f2178eed9bce81c320a969b41cd3a68519126a3d7d6258b77c6c51dfafd154dc58895b00c131a811734465da1fdcc17a7b8bb1c10e2b68
|
data/README.md
CHANGED
@@ -53,10 +53,32 @@ verses = ranges.map do |from_ref, to_ref|
|
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
56
|
-
##
|
56
|
+
## Single-Chapter Book Matching
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
Passing `single_chapter_book_matching` keyword to `Reference` changes how single-chapter books are handled.
|
59
|
+
It affects how something like `Jude 1` is parsed:
|
60
|
+
|
61
|
+
| setting | input | result |
|
62
|
+
|--------------------|--------|--------------------------|
|
63
|
+
| :special (default) | jude 1 | single verse of Jude 1:1 |
|
64
|
+
| :indifferent | jude 1 | whole chapter of Jude |
|
65
|
+
|
66
|
+
While the default of `:special` seems to match what most people expect, using the `:indifferent` setting will make `jude 1`
|
67
|
+
behave the same as something like `john 1` -- both will return the entire chapter.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
BibleRef::Reference.new('jude 1').ranges
|
71
|
+
# [
|
72
|
+
# [{ book: 'JUD', chapter: 1, verse: 1 },
|
73
|
+
# { book: 'JUD', chapter: 1, verse: 1 }]
|
74
|
+
# ]
|
75
|
+
|
76
|
+
BibleRef::Reference.new('jude 1', single_chapter_book_matching: :indifferent).ranges
|
77
|
+
# [
|
78
|
+
# [{ book: 'JUD', chapter: 1 },
|
79
|
+
# { book: 'JUD', chapter: 1 }]
|
80
|
+
# ]
|
81
|
+
```
|
60
82
|
|
61
83
|
## Copyright
|
62
84
|
|
data/lib/bible_ref/reference.rb
CHANGED
@@ -7,11 +7,13 @@ 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: 'all')
|
10
|
+
def initialize(reference, language: 'eng', canon: 'all', single_chapter_book_matching: :special)
|
11
11
|
@language = language.respond_to?(:book_id) ? language : LANGUAGES.fetch(language.to_s).new
|
12
12
|
@canon = canon.respond_to?(:books) ? canon : CANONS.fetch(canon.to_s).new
|
13
13
|
@reference = reference
|
14
|
-
|
14
|
+
@single_chapter_book_matching = single_chapter_book_matching
|
15
|
+
raise 'expected :special or :indifferent' unless %i[special indifferent].include?(@single_chapter_book_matching)
|
16
|
+
standardize_reference
|
15
17
|
@details = parse
|
16
18
|
end
|
17
19
|
|
@@ -75,17 +77,20 @@ module BibleRef
|
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
78
|
-
# standardize the reference so it can be handed to the parser.
|
79
80
|
def standardize_reference
|
80
|
-
|
81
|
-
|
81
|
+
standardize_single_chapter_book if @language.has_single_chapter?(@reference)
|
82
|
+
end
|
83
|
+
|
84
|
+
def standardize_single_chapter_book
|
85
|
+
return if @single_chapter_book_matching == :indifferent
|
86
|
+
return @reference if @reference.include? ':'
|
82
87
|
|
83
|
-
|
84
|
-
|
88
|
+
matches = @reference.match(/^([\d]?[\D\s]*)/)
|
89
|
+
return @reference if matches.length() == 0
|
85
90
|
|
86
|
-
|
87
|
-
|
88
|
-
|
91
|
+
book = matches[0].strip
|
92
|
+
requested = @reference.sub(book, '').strip
|
93
|
+
@reference = "#{book} 1:#{requested}"
|
89
94
|
end
|
90
95
|
|
91
96
|
def parse
|
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.9.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:
|
11
|
+
date: 2025-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|