bible_ref 1.1.4 → 1.5.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: 60e2dfcac1d655696dae057ac1c3b0a1d946d30aa3227eeecca5f6857622276c
4
- data.tar.gz: f5100ac7b741b9fb57baecea60581b1b61e65a18891e9a3271840ebb73ce2966
3
+ metadata.gz: 28631c2deed7edc4e9d018a03e9cbce155028deeaa8d5149b8a1e57bf1812a21
4
+ data.tar.gz: d66be495db2c250116a6988e40752db5c18ed9ab4143572f3843a21be959a9ad
5
5
  SHA512:
6
- metadata.gz: b776331cbf41a6dcc3a9be38945cf08b003246c258bebce377a23d5338529ef01ec73cc3f0c8abb1d0aa8234da1f6b8604ae613b6d94afd29f9f048dc3e53030
7
- data.tar.gz: ca2d55457a2783c8bce2a0df58267d1142fc3cca1c08c64f828da67c6a1dc7144c724c6f2abdf96e8370308e087c6ee5695f3e7d84a2cf0ab0faba43940993b4
6
+ metadata.gz: 320349a57e409a9af89a6ce807c7ce87bdf693a51105e2eb65c895192419d48c628915e3c96ab8878c5eeedd420e9e2b2f05057620aceafbd0df5545450e716e
7
+ data.tar.gz: 750fc6c150ea10c2493c0944cc4e10c203e56b89abf5284fca6fbe880afce0e6f839f3589b0fa3a07aefcdab55df5009b1a94502ea9a03e3e2d06af6349f3f16
data/README.md CHANGED
@@ -53,6 +53,11 @@ verses = ranges.map do |from_ref, to_ref|
53
53
  end
54
54
  ```
55
55
 
56
+ ## Note
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.
60
+
56
61
  ## Copyright
57
62
 
58
63
  Copyright [Tim Morgan](http://timmorgan.org). Licensed MIT.
@@ -1,7 +1,8 @@
1
1
  require_relative 'canons/protestant'
2
-
2
+ require_relative 'canons/all'
3
3
  module BibleRef
4
4
  CANONS = {
5
- 'protestant' => Canons::Protestant
5
+ 'protestant' => Canons::Protestant,
6
+ 'all' => Canons::All
6
7
  }
7
8
  end
@@ -0,0 +1,15 @@
1
+ module BibleRef
2
+ module Canons
3
+ class All
4
+ def books
5
+ %w(
6
+ GEN EXO LEV NUM DEU JOS JDG RUT 1SA 2SA 1KI 2KI 1CH 2CH EZR NEH EST JOB
7
+ PSA PRO ECC SNG ISA JER LAM EZK DAN HOS JOL AMO OBA JON MIC NAM HAB ZEP HAG
8
+ ZEC MAL TOB JDT ESG WIS SIR BAR LJE S3Y SUS BEL 1MA 2MA 1ES MAN PS2 3MA 2ES
9
+ 4MA MAT MRK LUK JHN ACT ROM 1CO 2CO GAL EPH PHP COL 1TH 2TH 1TI 2TI TIT PHM
10
+ HEB JAS 1PE 2PE 1JN 2JN 3JN JUD REV
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative 'languages/cherokee'
2
2
  require_relative 'languages/english'
3
+ require_relative 'languages/latin'
3
4
  require_relative 'languages/portuguese'
4
5
  require_relative 'languages/romanian'
5
6
 
@@ -7,7 +8,8 @@ module BibleRef
7
8
  LANGUAGES = {
8
9
  'chr' => Languages::Cherokee,
9
10
  'eng' => Languages::English,
11
+ 'lat' => Languages::Latin,
10
12
  'por' => Languages::Portuguese,
11
13
  'ron' => Languages::Romanian
12
- }
14
+ }.freeze
13
15
  end
@@ -5,6 +5,11 @@ module BibleRef
5
5
  fail NotImplementedError, "You must override #books in your language class."
6
6
  end
7
7
 
8
+ # Is it a single chapter book?
9
+ def has_single_chapter?(reference)
10
+ fail NotImplementedError, "You must override #has_single_chapter? in your language class."
11
+ end
12
+
8
13
  def book_id(book_name, canon)
9
14
  book_name = replace_roman_numerals(book_name)
10
15
  return book_name.upcase if books[book_name.upcase] # already normalized
@@ -12,9 +17,9 @@ module BibleRef
12
17
  details = books[book]
13
18
  next if details.nil?
14
19
  if (match = details[:match])
15
- return book if book_name =~ match
20
+ return book if book_name.downcase =~ match
16
21
  else
17
- return book if book_name == details[:name]
22
+ return book if book_name.downcase == details[:name].downcase
18
23
  end
19
24
  end
20
25
  nil
@@ -4,6 +4,13 @@ require_relative 'base'
4
4
  module BibleRef
5
5
  module Languages
6
6
  class Cherokee < Base
7
+
8
+ # Is it a single chapter book?
9
+ def has_single_chapter?(reference)
10
+ matches = ['ᏉᎳ ᏆᎵᎹᏂ ᎤᏬᏪᎳᏁᎸᎯ', 'ᏣᏂ ᏔᎵᏁ ᎤᏬᏪᎳᏅᎯ', 'ᏣᏂ ᏦᎢᏁ ᎤᏬᏪᎳᏅᎯ', 'ᏧᏓᏏ ᎤᏬᏪᎳᏅᎯ']
11
+ return matches.any? { |e| reference.include?(e) }
12
+ end
13
+
7
14
  def books
8
15
  {
9
16
  'MAT' => { name: 'ᎣᏍᏛ ᎧᏃᎮᏛ ᎹᏚ ᎤᏬᏪᎳᏅᎯ' },
@@ -4,6 +4,13 @@ require_relative 'base'
4
4
  module BibleRef
5
5
  module Languages
6
6
  class English < Base
7
+
8
+ # Is it a single chapter book?
9
+ def has_single_chapter?(reference)
10
+ matches = [/^ob/, /^(jude|jd(?!th)|jud(?!ith)(?!ges))/, /^2 ?jo?h?n/, /^3 ?jo?h?n/, /^ph(i?l|m)/]
11
+ return Regexp.union(matches).match?(reference.downcase)
12
+ end
13
+
7
14
  def books
8
15
  {
9
16
  'GEN' => { match: /^gen/, name: 'Genesis' },
@@ -46,7 +53,7 @@ module BibleRef
46
53
  'ZEC' => { match: /^zec/, name: 'Zechariah' },
47
54
  'MAL' => { match: /^mal/, name: 'Malachi' },
48
55
  'TOB' => { match: /^tob/, name: 'Tobit' },
49
- 'JDT' => { match: /^(jud|jdt)/, name: 'Judith' },
56
+ 'JDT' => { match: /^(jth|jdth?|judith)/, name: 'Judith' },
50
57
  'ESG' => { match: /^(est.*greek|esg)/, name: 'Esther (Greek)' },
51
58
  'WIS' => { match: /^wis(dom)?/, name: 'Wisdom of Solomon' },
52
59
  'SIR' => { match: /^sir/, name: 'Sirach' },
@@ -64,7 +71,7 @@ module BibleRef
64
71
  '2ES' => { match: /^2 ?esd?/, name: '2 Esdras' },
65
72
  '4MA' => { match: /^4 ?mac?/, name: '4 Maccabees' },
66
73
  'MAT' => { match: /^mat/, name: 'Matthew' },
67
- 'MRK' => { match: /^ma?rk/, name: 'Mark' },
74
+ 'MRK' => { match: /^(ma?rk|mk)/, name: 'Mark' },
68
75
  'LUK' => { match: /^lu?k/, name: 'Luke' },
69
76
  'JHN' => { match: /^(john|jn|jhn)/, name: 'John' },
70
77
  'ACT' => { match: /^act/, name: 'Acts' },
@@ -88,7 +95,7 @@ module BibleRef
88
95
  '1JN' => { match: /^1 ?jo?h?n/, name: '1 John' },
89
96
  '2JN' => { match: /^2 ?jo?h?n/, name: '2 John' },
90
97
  '3JN' => { match: /^3 ?jo?h?n/, name: '3 John' },
91
- 'JUD' => { match: /^jud/, name: 'Jude' },
98
+ 'JUD' => { match: /^(jud$|jd$|jude$)/, name: 'Jude' },
92
99
  'REV' => { match: /^re?v/, name: 'Revelation' }
93
100
  }
94
101
  end
@@ -0,0 +1,85 @@
1
+ # -*- coding: utf-8 -*-
2
+ require_relative 'base'
3
+
4
+ module BibleRef
5
+ module Languages
6
+ class Latin < Base
7
+ # Is it a single chapter book?
8
+ def has_single_chapter?(reference)
9
+ matches = ['Abdias', 'ad Philemonem', 'Joannis II', 'Joannis III', 'Judæ']
10
+ return matches.any? { |e| reference.include?(e) }
11
+ end
12
+
13
+ def books
14
+ {
15
+ 'GEN' => { name: 'Genesis' },
16
+ 'EXO' => { name: 'Exodus' },
17
+ 'LEV' => { name: 'Leviticus' },
18
+ 'NUM' => { name: 'Numeri' },
19
+ 'DEU' => { name: 'Deuteronomium' },
20
+ 'JOS' => { name: 'Josue' },
21
+ 'JDG' => { name: 'Judicum' },
22
+ 'RUT' => { name: 'Ruth' },
23
+ '1SA' => { name: 'Regum I' },
24
+ '2SA' => { name: 'Regum II' },
25
+ '1KI' => { name: 'Regum III' },
26
+ '2KI' => { name: 'Regum IV' },
27
+ '1CH' => { name: 'Paralipomenon I' },
28
+ '2CH' => { name: 'Paralipomenon II' },
29
+ 'EZR' => { name: 'Esdræ' },
30
+ 'NEH' => { name: 'Nehemiæ' },
31
+ 'EST' => { name: 'Tobiæ' },
32
+ 'JOB' => { name: 'Job' },
33
+ 'PSA' => { name: 'Psalmi' },
34
+ 'PRO' => { name: 'Proverbia' },
35
+ 'ECC' => { name: 'Ecclesiastes' },
36
+ 'SNG' => { name: 'Canticum Canticorum' },
37
+ 'ISA' => { name: 'Isaias' },
38
+ 'JER' => { name: 'Jeremias' },
39
+ 'LAM' => { name: 'Lamentationes' },
40
+ 'EZK' => { name: 'Ezechiel' },
41
+ 'DAN' => { name: 'Daniel' },
42
+ 'HOS' => { name: 'Osee' },
43
+ 'JOL' => { name: 'Joël' },
44
+ 'AMO' => { name: 'Amos' },
45
+ 'OBA' => { name: 'Abdias' },
46
+ 'JON' => { name: 'Jonas' },
47
+ 'MIC' => { name: 'Michæa' },
48
+ 'NAM' => { name: 'Nahum' },
49
+ 'HAB' => { name: 'Habacuc' },
50
+ 'ZEP' => { name: 'Sophonias' },
51
+ 'HAG' => { name: 'Aggæus' },
52
+ 'ZEC' => { name: 'Zacharias' },
53
+ 'MAL' => { name: 'Malachias' },
54
+ 'MAT' => { name: 'Matthæus' },
55
+ 'MRK' => { name: 'Marcus' },
56
+ 'LUK' => { name: 'Lucas' },
57
+ 'JHN' => { name: 'Joannes' },
58
+ 'ACT' => { name: 'Actus Apostolorum' },
59
+ 'ROM' => { name: 'ad Romanos' },
60
+ '1CO' => { name: 'ad Corinthios I' },
61
+ '2CO' => { name: 'ad Corinthios II' },
62
+ 'GAL' => { name: 'ad Galatas' },
63
+ 'EPH' => { name: 'ad Ephesios' },
64
+ 'PHP' => { name: 'ad Philippenses' },
65
+ 'COL' => { name: 'ad Colossenses' },
66
+ '1TH' => { name: 'ad Thessalonicenses I' },
67
+ '2TH' => { name: 'ad Thessalonicenses II' },
68
+ '1TI' => { name: 'ad Timotheum I' },
69
+ '2TI' => { name: 'ad Timotheum II' },
70
+ 'TIT' => { name: 'ad Titum' },
71
+ 'PHM' => { name: 'ad Philemonem' },
72
+ 'HEB' => { name: 'ad Hebræos' },
73
+ 'JAS' => { name: 'Jacobi' },
74
+ '1PE' => { name: 'Petri I' },
75
+ '2PE' => { name: 'Petri II' },
76
+ '1JN' => { name: 'Joannis I' },
77
+ '2JN' => { name: 'Joannis II' },
78
+ '3JN' => { name: 'Joannis III' },
79
+ 'JUD' => { name: 'Judæ' },
80
+ 'REV' => { name: 'Apocalypsis' }
81
+ }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -4,6 +4,13 @@ require_relative 'base'
4
4
  module BibleRef
5
5
  module Languages
6
6
  class Portuguese < Base
7
+
8
+ # Is it a single chapter book?
9
+ def has_single_chapter?(reference)
10
+ matches = [/^ob/, /^jud/, /^2 jo/, /^3 jo/, /^fil/]
11
+ return Regexp.union(matches).match?(reference.downcase)
12
+ end
13
+
7
14
  def books
8
15
  {
9
16
  'GEN' => { match: /^g[eê]n/, name: 'Gênesis' },
@@ -46,7 +53,7 @@ module BibleRef
46
53
  'ZEC' => { match: /^zac/, name: 'Zacarias' },
47
54
  'MAL' => { match: /^mal/, name: 'Malaquias' },
48
55
  'MAT' => { match: /^mat/, name: 'Mateus' },
49
- 'MRK' => { match: /^mar/, name: 'Marcos' },
56
+ 'MRK' => { match: /^(mar|mk)/, name: 'Marcos' },
50
57
  'LUK' => { match: /^lu/, name: 'Lucas' },
51
58
  'JHN' => { match: /^jo/, name: 'João' },
52
59
  'ACT' => { match: /^at/, name: 'Atos' },
@@ -4,6 +4,13 @@ require_relative 'base'
4
4
  module BibleRef
5
5
  module Languages
6
6
  class Romanian < Base
7
+
8
+ # Is it a single chapter book?
9
+ def has_single_chapter?(reference)
10
+ matches = [/^ob/, /^iud/, /^2 io/, /^3 io/, /^fil/]
11
+ return Regexp.union(matches).match?(reference.downcase)
12
+ end
13
+
7
14
  def books
8
15
  {
9
16
  'GEN' => { match: /^gen/, name: 'Geneza' },
@@ -46,7 +53,7 @@ module BibleRef
46
53
  'ZEC' => { match: /^za/, name: 'Zaharia' },
47
54
  'MAL' => { match: /^mal/, name: 'Maleahi' },
48
55
  'MAT' => { match: /^mat/, name: 'Matei' },
49
- 'MRK' => { match: /^mar/, name: 'Marcu' },
56
+ 'MRK' => { match: /^(mar|mk)/, name: 'Marcu' },
50
57
  'LUK' => { match: /^lu/, name: 'Luca' },
51
58
  'JHN' => { match: /^io/, name: 'Ioan' },
52
59
  'ACT' => { match: /^fa/, name: 'Faptele apostolilor' },
@@ -7,11 +7,12 @@ 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: 'protestant')
11
- @reference = reference
12
- @details = parse
10
+ def initialize(reference, language: 'eng', canon: 'all')
13
11
  @language = language.respond_to?(:book_id) ? language : LANGUAGES.fetch(language.to_s).new
14
12
  @canon = canon.respond_to?(:books) ? canon : CANONS.fetch(canon.to_s).new
13
+ @reference = reference
14
+ standardize_reference()
15
+ @details = parse
15
16
  end
16
17
 
17
18
  # Returns an array of pairs, each one being the from and to for a range.
@@ -22,7 +23,6 @@ module BibleRef
22
23
  def ranges
23
24
  return nil unless valid?
24
25
  @chapter = nil
25
- fix_chapter_for_jude if book_id == 'JUD'
26
26
  [@details[:refs]].flatten.map do |ref|
27
27
  normalize_range(ref) || normalize_ref(ref)
28
28
  end
@@ -75,6 +75,19 @@ module BibleRef
75
75
  end
76
76
  end
77
77
 
78
+ # standardize the reference so it can be handed to the parser.
79
+ def standardize_reference
80
+ return @reference unless @language.has_single_chapter?(@reference)
81
+ return @reference if @reference.include? ':'
82
+
83
+ matches = @reference.match(/^([\d]?[\D\s]*)/)
84
+ return @reference if matches.length() == 0
85
+
86
+ book = matches[0].strip
87
+ requested = @reference.sub(book, '').strip
88
+ @reference = "#{book} 1:#{requested}"
89
+ end
90
+
78
91
  def parse
79
92
  begin
80
93
  parsed = Parser.new.parse(@reference)
@@ -102,23 +115,5 @@ module BibleRef
102
115
  end
103
116
  end
104
117
 
105
- def fix_chapter_for_jude
106
- (start, finish) = @details[:refs]
107
- finish ||= start
108
- @details[:refs] = [
109
- {
110
- range: {
111
- from: {
112
- chapter: 1,
113
- verse: start[:chapter]
114
- },
115
- to: {
116
- chapter: 1,
117
- verse: finish[:chapter]
118
- }
119
- }
120
- }
121
- ]
122
- end
123
118
  end
124
119
  end
@@ -1,3 +1,3 @@
1
1
  module BibleRef
2
- VERSION = '1.1.4'
2
+ VERSION = '1.5.1'
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.1.4
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Morgan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-03 00:00:00.000000000 Z
11
+ date: 2020-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -62,11 +62,13 @@ files:
62
62
  - README.md
63
63
  - lib/bible_ref.rb
64
64
  - lib/bible_ref/canons.rb
65
+ - lib/bible_ref/canons/all.rb
65
66
  - lib/bible_ref/canons/protestant.rb
66
67
  - lib/bible_ref/languages.rb
67
68
  - lib/bible_ref/languages/base.rb
68
69
  - lib/bible_ref/languages/cherokee.rb
69
70
  - lib/bible_ref/languages/english.rb
71
+ - lib/bible_ref/languages/latin.rb
70
72
  - lib/bible_ref/languages/portuguese.rb
71
73
  - lib/bible_ref/languages/romanian.rb
72
74
  - lib/bible_ref/parser.rb
@@ -76,7 +78,7 @@ homepage: https://github.com/seven1m/bible_ref
76
78
  licenses:
77
79
  - MIT
78
80
  metadata: {}
79
- post_install_message:
81
+ post_install_message:
80
82
  rdoc_options: []
81
83
  require_paths:
82
84
  - lib
@@ -91,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  - !ruby/object:Gem::Version
92
94
  version: '0'
93
95
  requirements: []
94
- rubygems_version: 3.0.2
95
- signing_key:
96
+ rubygems_version: 3.1.2
97
+ signing_key:
96
98
  specification_version: 4
97
99
  summary: Bible reference parser
98
100
  test_files: []