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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22b821510013daef3716627d59856edc01762529d3c86d03e0ccf444333c6af5
4
- data.tar.gz: 4d9bae58173393fa318c2a7cda11840e18f26b31ebfa70a7bf0ca18ca87eaae1
3
+ metadata.gz: a9f9a5343547b1777a07bb2876bf17b38e31225c1948571a85588758a8f3d915
4
+ data.tar.gz: 8d1d69e4b6b97bdb6d675ec1584b6abb45b5c2a7b2731ea7647443f7bc5c0138
5
5
  SHA512:
6
- metadata.gz: f1bb301a9c6a10a0f1d561da1407c87fe3986dd4b668eae6f8eb42c25cdb8bd1d31f0937f9b566db8434faee6956e02235083f9543cf9c5648acc663425a7313
7
- data.tar.gz: e25f90e6a2bcb740061d547a3760750a93b699f82c66f4a0fa4e6626480658eb7b95ad1c7b4bde63433c654a798e538e5dd95e0a3dd8898fbf80c2374584b828
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
- ## Note
56
+ ## Single-Chapter Book Matching
57
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.
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
 
@@ -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
- standardize_reference()
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
- return @reference unless @language.has_single_chapter?(@reference)
81
- return @reference if @reference.include? ':'
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
- matches = @reference.match(/^([\d]?[\D\s]*)/)
84
- return @reference if matches.length() == 0
88
+ matches = @reference.match(/^([\d]?[\D\s]*)/)
89
+ return @reference if matches.length() == 0
85
90
 
86
- book = matches[0].strip
87
- requested = @reference.sub(book, '').strip
88
- @reference = "#{book} 1:#{requested}"
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
@@ -1,3 +1,3 @@
1
1
  module BibleRef
2
- VERSION = '1.8.1'
2
+ VERSION = '1.9.0'
3
3
  end
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.8.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: 2024-12-27 00:00:00.000000000 Z
11
+ date: 2025-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet