bible_ref 1.8.1 → 1.9.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22b821510013daef3716627d59856edc01762529d3c86d03e0ccf444333c6af5
4
- data.tar.gz: 4d9bae58173393fa318c2a7cda11840e18f26b31ebfa70a7bf0ca18ca87eaae1
3
+ metadata.gz: 8e0b787413a48a2a6788eaec420755be004d9ed32786c9a105e3025507a2e843
4
+ data.tar.gz: '03793a39b9ceeca6043620322be60201d5d4ce3238946a9e08eb933afa901c9a'
5
5
  SHA512:
6
- metadata.gz: f1bb301a9c6a10a0f1d561da1407c87fe3986dd4b668eae6f8eb42c25cdb8bd1d31f0937f9b566db8434faee6956e02235083f9543cf9c5648acc663425a7313
7
- data.tar.gz: e25f90e6a2bcb740061d547a3760750a93b699f82c66f4a0fa4e6626480658eb7b95ad1c7b4bde63433c654a798e538e5dd95e0a3dd8898fbf80c2374584b828
6
+ metadata.gz: 837e7f136544e11b9f8033e72d990de67280457312a8cf48b412ac6d9742a994003c2b39b791db9044fccc21dfa54ec21b4347f91ed7275b18055fbe5350d02c
7
+ data.tar.gz: 5a50e55e950dabe2988df1775332e89b8760886b5df82428d4d6b7994e7c138d1bca4b13971f4606449de1a51d531494b3c1c1a4677bcf6754035f53e70eba28
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
 
@@ -73,14 +73,14 @@ module BibleRef
73
73
  'HEB' => { match: /^希/, name: '希伯來書'},
74
74
  'JAS' => { match: /^雅各/, name: '雅各書'},
75
75
  '1PE' => { match: /^彼得前/, name: '彼得前書'},
76
- '2PE' => { match: /^彼得後/, name: '彼得前書'},
76
+ '2PE' => { match: /^彼得後/, name: '彼得後書'},
77
77
  '1JN' => { match: /壹書$/, name: '約翰壹書'},
78
- '2JH' => { match: /貳書$/, name: '約翰貳書'},
79
- '3JH' => { match: /參書$/, name: '約翰參書'},
78
+ '2JN' => { match: /貳書$/, name: '約翰貳書'},
79
+ '3JN' => { match: /參書$/, name: '約翰參書'},
80
80
  'JUD' => { match: /^猶/, name: '猶大書'},
81
81
  'REV' => { match: /^啟/, name: '啟示錄'}
82
82
  }
83
83
  end
84
84
  end
85
85
  end
86
- end
86
+ end
@@ -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.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Morgan
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: parslet
@@ -81,7 +80,6 @@ homepage: https://github.com/seven1m/bible_ref
81
80
  licenses:
82
81
  - MIT
83
82
  metadata: {}
84
- post_install_message:
85
83
  rdoc_options: []
86
84
  require_paths:
87
85
  - lib
@@ -96,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
94
  - !ruby/object:Gem::Version
97
95
  version: '0'
98
96
  requirements: []
99
- rubygems_version: 3.5.16
100
- signing_key:
97
+ rubygems_version: 3.6.7
101
98
  specification_version: 4
102
99
  summary: Bible reference parser
103
100
  test_files: []