bible_ref 0.2.1 → 1.0.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
  SHA1:
3
- metadata.gz: 694d21174ea7792cbd836f0cee4a3dedf63af0bc
4
- data.tar.gz: 4d46099efa929b7623add504ca322ff63eb0b9ad
3
+ metadata.gz: 68f998033defe0c1f8dc086834178c4d680380c2
4
+ data.tar.gz: 405ff445a3dc1a7ee78412dd84b783405f4fe2a2
5
5
  SHA512:
6
- metadata.gz: 39b71a97e6bf202687a272c4c86a6310b9a55e8ffe2306f2af99b9a57574a27ba8d11b448e30568abf383fa4fc55cc521664b2b1a93d703f2c6beda4765c1d76
7
- data.tar.gz: 11aee5b5db6cf40ec51d5796322a87996e35bf6ba9db53ffcc4aa2f649472709f92c3c794cffe5565c632a0002f359971b07166308a87f4b1ca8632bacee8377
6
+ metadata.gz: c646a6b5b7501d39822b10d298b14524cbc61e7a99b935f28b4100b9ecd00e300bd96097678cab49aa48e4de2c6d105cb5809dea83deac26cb7ed447efa7185c
7
+ data.tar.gz: 7891140a1831b033324e074321fdf1476044bfdc6731cdb64933ae514bb975ca68b0497fb643c0d6ac4363df1c9d02f0a2c0613113da6e00b2e7733eb6099f8b
data/README.md CHANGED
@@ -1,33 +1,58 @@
1
1
  # BibleRef
2
2
 
3
- Turn "John 3:16" into:
3
+ This small Rubygem does its best at taking a user-input string like "john 3:16" and turning it into something useful
4
+ for querying a database (this is how we use it in [bible_api](https://github.com/seven1m/bible_api)).
5
+
6
+ ## Usage
4
7
 
5
8
  ```ruby
6
- [
7
- [{ book: 'JHN', chapter: 3, verse: 16 },
8
- { book: 'JHN', chapter: 3, verse: 16 }]
9
- ]
9
+ ref = BibleRef::Reference.new('jn 3:16')
10
+ # #<BibleRef::Reference:0x000001020f7000 @reference="jn 3:16", @details={:book=>"jn", :refs=>{:chapter=>3, :verse=>16}}>
11
+
12
+ ref.valid?
13
+ # true
14
+
15
+ ref.book.id
16
+ # "JHN"
17
+
18
+ ref.normalize
19
+ # "John 3:16"
10
20
  ```
11
21
 
12
- ...and turn "Romans 12:1,3-4 & 13:2-4,7-8" into:
22
+ ## Ranges
23
+
24
+ Call `#ranges` to get from/to pairs of verses.
13
25
 
14
26
  ```ruby
15
- [
16
- [{ book: 'ROM', chapter: 12, verse: 1 },
17
- { book: 'ROM', chapter: 12, verse: 1 }],
18
- [{ book: 'ROM', chapter: 12, verse: 3 },
19
- { book: 'ROM', chapter: 12, verse: 4 }],
20
- [{ book: 'ROM', chapter: 13, verse: 2 },
21
- { book: 'ROM', chapter: 13, verse: 4 }],
22
- [{ book: 'ROM', chapter: 13, verse: 7 },
23
- { book: 'ROM', chapter: 13, verse: 8 }]
24
- ]
27
+ BibleRef::Reference.new('john 3:16').ranges
28
+ # [
29
+ # [{ book: 'JHN', chapter: 3, verse: 16 },
30
+ # { book: 'JHN', chapter: 3, verse: 16 }]
31
+ # ]
32
+
33
+ BibleRef::Reference.new('Romans 12:1,3-4 & 13:2-4,7-8').ranges
34
+ # [
35
+ # [{ book: 'ROM', chapter: 12, verse: 1 },
36
+ # { book: 'ROM', chapter: 12, verse: 1 }],
37
+ # [{ book: 'ROM', chapter: 12, verse: 3 },
38
+ # { book: 'ROM', chapter: 12, verse: 4 }],
39
+ # [{ book: 'ROM', chapter: 13, verse: 2 },
40
+ # { book: 'ROM', chapter: 13, verse: 4 }],
41
+ # [{ book: 'ROM', chapter: 13, verse: 7 },
42
+ # { book: 'ROM', chapter: 13, verse: 8 }]
43
+ # ]
25
44
  ```
26
45
 
27
- (We return from/to pairs for every range so to make querying a SQL database easy peasy.)
46
+ You can then take this and turn it into a few small SQL queries like this:
28
47
 
29
- See [the specs](https://github.com/seven1m/bible_ref/blob/master/spec/bible_ref/reference_spec.rb) for more examples.
48
+ ```ruby
49
+ verses = ranges.map do |from_ref, to_ref|
50
+ first = DB['select id from verses where book = :book and chapter = :chapter and verse = :verse limit 1', from_ref].first
51
+ last = DB['select id from verses where book = :book and chapter = :chapter and verse = :verse limit 1', to_ref].first
52
+ DB['select * from verses where id between ? and ?', first['id'], last['id']]
53
+ end
54
+ ```
30
55
 
31
56
  ## Copyright
32
57
 
33
- Copyright [Tim Morgan](http://timmorgan.org). See LICENSE.
58
+ Copyright [Tim Morgan](http://timmorgan.org). Licensed MIT.
@@ -0,0 +1,12 @@
1
+ module BibleRef
2
+ module Canons
3
+ class Protestant
4
+ def books
5
+ %w(
6
+ GEN EXO LEV NUM DEU JOS JDG RUT 1SA 2SA 1KI 2KI 1CH 2CH EZR NEH EST JOB PSA PRO ECC SNG ISA JER LAM EZK DAN HOS JOL AMO OBA JON MIC NAM HAB ZEP HAG ZEC MAL
7
+ MAT MRK LUK JHN ACT ROM 1CO 2CO GAL EPH PHP COL 1TH 2TH 1TI 2TI TIT PHM HEB JAS 1PE 2PE 1JN 2JN 3JN JUD REV
8
+ )
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'canons/protestant'
2
+
3
+ module BibleRef
4
+ CANONS = {
5
+ 'protestant' => Canons::Protestant
6
+ }
7
+ end
@@ -0,0 +1,31 @@
1
+ module BibleRef
2
+ module Languages
3
+ class Base
4
+ def books
5
+ fail NotImplementedError, "You must override #books in your language class."
6
+ end
7
+
8
+ def book_id(book_name, canon)
9
+ book_name = replace_roman_numerals(book_name.downcase)
10
+ return book_name.upcase if books[book_name.upcase] # already normalized
11
+ canon.books.each do |book|
12
+ match = books[book][:match]
13
+ return book if book_name =~ match
14
+ end
15
+ nil
16
+ end
17
+
18
+ def book_name(book_name, canon)
19
+ return unless id = book_id(book_name, canon)
20
+ books[id][:name]
21
+ end
22
+
23
+ def replace_roman_numerals(book)
24
+ book.sub!(/^iii/i, '3')
25
+ book.sub!(/^ii/i, '2')
26
+ book.sub!(/^i/i, '1')
27
+ book
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,97 @@
1
+ # -*- coding: utf-8 -*-
2
+ require_relative 'base'
3
+
4
+ module BibleRef
5
+ module Languages
6
+ class English < Base
7
+ def books
8
+ {
9
+ 'GEN' => { match: /^gen/, name: 'Genesis' },
10
+ 'EXO' => { match: /^ex/, name: 'Exodus' },
11
+ 'LEV' => { match: /^le?v/, name: 'Leviticus' },
12
+ 'NUM' => { match: /^nu/, name: 'Numbers' },
13
+ 'DEU' => { match: /^d(e?ut|eu)/, name: 'Deuteronomy' },
14
+ 'JOS' => { match: /^jos/, name: 'Joshua' },
15
+ 'JDG' => { match: /^ju?dg/, name: 'Judges' },
16
+ 'RUT' => { match: /^ru/, name: 'Ruth' },
17
+ '1SA' => { match: /^1 ?s(a?m|a)/, name: '1 Samuel' },
18
+ '2SA' => { match: /^2 ?s(a?m|a)/, name: '2 Samuel' },
19
+ '1KI' => { match: /^1 ?(king|kgs|ki)/, name: '1 Kings' },
20
+ '2KI' => { match: /^2 ?(king|kgs|ki)/, name: '2 Kings' },
21
+ '1CH' => { match: /^1 ?chr?/, name: '1 Chronicles' },
22
+ '2CH' => { match: /^2 ?chr?/, name: '2 Chronicles' },
23
+ 'EZR' => { match: /^ez/, name: 'Ezra' },
24
+ 'NEH' => { match: /^ne/, name: 'Nehemiah' },
25
+ 'EST' => { match: /^est/, name: 'Esther' },
26
+ 'JOB' => { match: /^jo?b/, name: 'Job' },
27
+ 'PSA' => { match: /^ps/, name: 'Psalms' },
28
+ 'PRO' => { match: /^(pro?v|pro)/, name: 'Proverbs' },
29
+ 'ECC' => { match: /^ecc/, name: 'Ecclesiastes' },
30
+ 'SNG' => { match: /^so?ng|^sol|^sg$/, name: 'Song of Solomon' },
31
+ 'ISA' => { match: /^isa/, name: 'Isaiah' },
32
+ 'JER' => { match: /^jer/, name: 'Jeremiah' },
33
+ 'LAM' => { match: /^lam/, name: 'Lamentations' },
34
+ 'EZK' => { match: /^ez/, name: 'Ezekiel' },
35
+ 'DAN' => { match: /^dan/, name: 'Daniel' },
36
+ 'HOS' => { match: /^hos/, name: 'Hosea' },
37
+ 'JOL' => { match: /^joe?l/, name: 'Joel' },
38
+ 'AMO' => { match: /^amo/, name: 'Amos' },
39
+ 'OBA' => { match: /^ob/, name: 'Obadiah' },
40
+ 'JON' => { match: /^jona?/, name: 'Jonah' },
41
+ 'MIC' => { match: /^mi/, name: 'Micah' },
42
+ 'NAM' => { match: /^na(h|m)/, name: 'Nahum' },
43
+ 'HAB' => { match: /^hab/, name: 'Habakkuk' },
44
+ 'ZEP' => { match: /^zep/, name: 'Zephaniah' },
45
+ 'HAG' => { match: /^hag/, name: 'Haggai' },
46
+ 'ZEC' => { match: /^zec/, name: 'Zechariah' },
47
+ 'MAL' => { match: /^mal/, name: 'Malachi' },
48
+ 'TOB' => { match: /^tob/, name: 'Tobit' },
49
+ 'JDT' => { match: /^(jud|jdt)/, name: 'Judith' },
50
+ 'ESG' => { match: /^(est.*greek|esg)/, name: 'Esther (Greek)' },
51
+ 'WIS' => { match: /^wis(dom)?/, name: 'Wisdom of Solomon' },
52
+ 'SIR' => { match: /^sir/, name: 'Sirach' },
53
+ 'BAR' => { match: /^bar/, name: 'Baruch' },
54
+ 'LJE' => { match: /^(jeremy|lje)/, name: 'Jeremy’s Letter' },
55
+ 'S3Y' => { match: /^(3 holy|s3y)/, name: '3 Holy Children’s Song' },
56
+ 'SUS' => { match: /^sus/, name: 'Susanna' },
57
+ 'BEL' => { match: /^bel/, name: 'Bel and the Dragon' },
58
+ '1MA' => { match: /^1 ?mac?/, name: '1 Maccabees' },
59
+ '2MA' => { match: /^2 ?mac?/, name: '2 Maccabees' },
60
+ '1ES' => { match: /^1 ?esd?/, name: '1 Esdras' },
61
+ 'MAN' => { match: /^(prayer|man)/, name: 'Prayer of Manasses' },
62
+ 'PS2' => { match: /^(psalm 151|ps2)/, name: 'Psalm 151' },
63
+ '3MA' => { match: /^3 ?mac?/, name: '3 Maccabees' },
64
+ '2ES' => { match: /^2 ?esd?/, name: '2 Esdras' },
65
+ '4MA' => { match: /^4 ?mac?/, name: '4 Maccabees' },
66
+ 'MAT' => { match: /^mat/, name: 'Matthew' },
67
+ 'MRK' => { match: /^ma?rk/, name: 'Mark' },
68
+ 'LUK' => { match: /^lu?k/, name: 'Luke' },
69
+ 'JHN' => { match: /^(john|jn|jhn)/, name: 'John' },
70
+ 'ACT' => { match: /^act/, name: 'Acts' },
71
+ 'ROM' => { match: /^rom/, name: 'Romans' },
72
+ '1CO' => { match: /^1 ?cor?/, name: '1 Corinthians' },
73
+ '2CO' => { match: /^2 ?cor?/, name: '2 Corinthians' },
74
+ 'GAL' => { match: /^gal/, name: 'Galatians' },
75
+ 'EPH' => { match: /^eph/, name: 'Ephesians' },
76
+ 'PHP' => { match: /^(phil|php)/, name: 'Philippians' },
77
+ 'COL' => { match: /^col/, name: 'Colossians' },
78
+ '1TH' => { match: /^1 ?the?s?/, name: '1 Thessalonians' },
79
+ '2TH' => { match: /^2 ?the?s?/, name: '2 Thessalonians' },
80
+ '1TI' => { match: /^1 ?tim?/, name: '1 Timothy' },
81
+ '2TI' => { match: /^2 ?tim?/, name: '2 Timothy' },
82
+ 'TIT' => { match: /^tit/, name: 'Titus' },
83
+ 'PHM' => { match: /^ph(i?l|m)/, name: 'Philemon' },
84
+ 'HEB' => { match: /^heb/, name: 'Hebrews' },
85
+ 'JAS' => { match: /^ja(m|s)/, name: 'James' },
86
+ '1PE' => { match: /^1 ?pet?/, name: '1 Peter' },
87
+ '2PE' => { match: /^2 ?pet?/, name: '2 Peter' },
88
+ '1JN' => { match: /^1 ?jo?h?n/, name: '1 John' },
89
+ '2JN' => { match: /^2 ?jo?h?n/, name: '2 John' },
90
+ '3JN' => { match: /^3 ?jo?h?n/, name: '3 John' },
91
+ 'JUD' => { match: /^jud/, name: 'Jude' },
92
+ 'REV' => { match: /^re?v/, name: 'Revelation' }
93
+ }
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,79 @@
1
+ # -*- coding: utf-8 -*-
2
+ require_relative 'base'
3
+
4
+ module BibleRef
5
+ module Languages
6
+ class Portuguese < Base
7
+ def books
8
+ {
9
+ 'GEN' => { match: /^g[eê]n/, name: 'Gênesis' },
10
+ 'EXO' => { match: /^[eê]x/, name: 'Êxodo' },
11
+ 'LEV' => { match: /^le?v/, name: 'Levítico' },
12
+ 'NUM' => { match: /^n[uú]/, name: 'Números' },
13
+ 'DEU' => { match: /^de?ut/, name: 'Deuteronômio' },
14
+ 'JOS' => { match: /^jos/, name: 'Josué' },
15
+ 'JDG' => { match: /^ju/, name: 'Juízes' },
16
+ 'RUT' => { match: /^ru/, name: 'Rute' },
17
+ '1SA' => { match: /^1 sa?m/, name: '1 Samuel' },
18
+ '2SA' => { match: /^2 sa?m/, name: '2 Samuel' },
19
+ '1KI' => { match: /^1 r/, name: '1 Reis' },
20
+ '2KI' => { match: /^2 r/, name: '2 Reis' },
21
+ '1CH' => { match: /^1 cr/, name: '1 Crônicas' },
22
+ '2CH' => { match: /^2 cr/, name: '2 Crônicas' },
23
+ 'EZR' => { match: /^esd/, name: 'Esdras' },
24
+ 'NEH' => { match: /^ne/, name: 'Neemias' },
25
+ 'EST' => { match: /^est/, name: 'Ester' },
26
+ 'JOB' => { match: /^j[oó]$/, name: 'Jó' },
27
+ 'PSA' => { match: /^sal/, name: 'Salmos' },
28
+ 'PRO' => { match: /^pro?v/, name: 'Provérbios' },
29
+ 'ECC' => { match: /^ecl/, name: 'Eclesiastes' },
30
+ 'SNG' => { match: /^c[aâ]n$/, name: 'Cânticos' },
31
+ 'ISA' => { match: /^isa/, name: 'Isaías' },
32
+ 'JER' => { match: /^jer/, name: 'Jeremias' },
33
+ 'LAM' => { match: /^lam/, name: 'Lamentações' },
34
+ 'EZK' => { match: /^ez/, name: 'Ezequiel' },
35
+ 'DAN' => { match: /^dan/, name: 'Daniel' },
36
+ 'HOS' => { match: /^os/, name: 'Oséias' },
37
+ 'JOL' => { match: /^joel/, name: 'Joel' },
38
+ 'AMO' => { match: /^am[oó]/, name: 'Amós' },
39
+ 'OBA' => { match: /^ob/, name: 'Obadias' },
40
+ 'JON' => { match: /^jona/, name: 'Jonas' },
41
+ 'MIC' => { match: /^mi/, name: 'Miquéias' },
42
+ 'NAM' => { match: /^nau/, name: 'Naum' },
43
+ 'HAB' => { match: /^hab/, name: 'Habacuque' },
44
+ 'ZEP' => { match: /^sof/, name: 'Sofonias' },
45
+ 'HAG' => { match: /^ag/, name: 'Ageu' },
46
+ 'ZEC' => { match: /^zac/, name: 'Zacarias' },
47
+ 'MAL' => { match: /^mal/, name: 'Malaquias' },
48
+ 'MAT' => { match: /^mat/, name: 'Mateus' },
49
+ 'MRK' => { match: /^mar/, name: 'Marcos' },
50
+ 'LUK' => { match: /^lu/, name: 'Lucas' },
51
+ 'JHN' => { match: /^jo/, name: 'João' },
52
+ 'ACT' => { match: /^at/, name: 'Atos' },
53
+ 'ROM' => { match: /^rom/, name: 'Romanos' },
54
+ '1CO' => { match: /^1 cor/, name: '1 Coríntios' },
55
+ '2CO' => { match: /^2 cor/, name: '2 Coríntios' },
56
+ 'GAL' => { match: /^g[aá]l/, name: 'Gálatas' },
57
+ 'EPH' => { match: /^ef[eé]/, name: 'Efésios' },
58
+ 'PHP' => { match: /^fil/, name: 'Filipenses' },
59
+ 'COL' => { match: /^col/, name: 'Colossenses' },
60
+ '1TH' => { match: /^1 te?s/, name: '1 Tessalonicenses' },
61
+ '2TH' => { match: /^2 te?s/, name: '2 Tessalonicenses' },
62
+ '1TI' => { match: /^1 tim/, name: '1 Timóteo' },
63
+ '2TI' => { match: /^2 tim/, name: '2 Timóteo' },
64
+ 'TIT' => { match: /^tit/, name: 'Tito' },
65
+ 'PHM' => { match: /^fil/, name: 'Filemom' },
66
+ 'HEB' => { match: /^heb/, name: 'Hebreus' },
67
+ 'JAS' => { match: /^tia/, name: 'Tiago' },
68
+ '1PE' => { match: /^1 ped/, name: '1 Pedro' },
69
+ '2PE' => { match: /^2 ped/, name: '2 Pedro' },
70
+ '1JN' => { match: /^1 jo/, name: '1 João' },
71
+ '2JN' => { match: /^2 jo/, name: '2 João' },
72
+ '3JN' => { match: /^3 jo/, name: '3 João' },
73
+ 'JUD' => { match: /^jud/, name: 'Judas' },
74
+ 'REV' => { match: /^apo/, name: 'Apocalipse' }
75
+ }
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'languages/english'
2
+ require_relative 'languages/portuguese'
3
+
4
+ module BibleRef
5
+ LANGUAGES = {
6
+ 'eng' => Languages::English,
7
+ 'por' => Languages::Portuguese
8
+ }
9
+ end
@@ -21,7 +21,7 @@ module BibleRef
21
21
  rule(:chapter) { num.as(:chapter) }
22
22
  rule(:verse) { num.as(:verse) }
23
23
 
24
- rule(:word) { (match("[0-9]").maybe >> match("[A-Za-z ]").repeat(1)).as(:word) }
24
+ rule(:word) { (match("[123]").maybe >> match("[^0-9]").repeat(1)).as(:word) }
25
25
  rule(:separator) { (str(",") >> space.maybe) | (space.maybe >> str("&") >> space.maybe) }
26
26
  rule(:num) { match("[0-9]").repeat(1).as(:num) }
27
27
  rule(:space) { str(" ").repeat(1) }
@@ -1,16 +1,17 @@
1
- require_relative './book'
1
+ require_relative './languages'
2
+ require_relative './canons'
2
3
  require_relative './parser'
3
4
 
4
5
  module BibleRef
5
6
  class Reference
6
-
7
- attr_reader :book
8
- attr_reader :reference
7
+ attr_reader :book, :reference, :language, :canon
9
8
 
10
9
  # Create a new Reference instance by passing in the user-supplied bible reference as a string.
11
- def initialize(reference)
10
+ def initialize(reference, language: 'eng', canon: 'protestant')
12
11
  @reference = reference
13
12
  @details = parse
13
+ @language = language.respond_to?(:book_id) ? language : LANGUAGES.fetch(language.to_s).new
14
+ @canon = canon.respond_to?(:books) ? canon : CANONS.fetch(canon.to_s).new
14
15
  end
15
16
 
16
17
  # Returns an array of pairs, each one being the from and to for a range.
@@ -26,23 +27,29 @@ module BibleRef
26
27
  end
27
28
  end
28
29
 
29
- # Returns a BibleRef::Book instance or nil if book not known.
30
- def book
30
+ # Returns a USFX-compatible book id, or nil if book is unknown.
31
+ def book_id
32
+ return nil unless @details
33
+ @book_id ||= @language.book_id(@details[:book], @canon)
34
+ end
35
+
36
+ # Returns the formatted book name
37
+ def book_name
31
38
  return nil unless @details
32
- @book ||= Book.new(@details[:book])
39
+ @book_name ||= @language.book_name(@details[:book], @canon)
33
40
  end
34
41
 
35
42
  # Returns true if the reference is a known bible passage.
36
43
  def valid?
37
- @details and book.id
44
+ @details && !book_id.nil?
38
45
  end
39
46
 
40
47
  # Returns a normalized passage reference. e.g.
41
48
  #
42
49
  # 'JOHN 3:16&17' => 'John 3:16,17'
43
50
  def normalize
44
- return unless book and ranges
45
- book.formatted + ' ' +
51
+ return unless book_id and ranges
52
+ book_name + ' ' +
46
53
  ranges.map do |(ref_from, ref_to)|
47
54
  if ref_from != ref_to
48
55
  ref_part(ref_from) + '-' + ref_part(ref_to)
@@ -57,7 +64,11 @@ module BibleRef
57
64
  def ref_part(ref)
58
65
  if @last_chapter != ref[:chapter] and ref[:chapter]
59
66
  @last_chapter = ref[:chapter]
60
- "#{ref[:chapter]}:#{ref[:verse]}"
67
+ if ref[:verse]
68
+ "#{ref[:chapter]}:#{ref[:verse]}"
69
+ else
70
+ ref[:chapter]
71
+ end
61
72
  else
62
73
  ref[:verse].to_s
63
74
  end
@@ -78,15 +89,15 @@ module BibleRef
78
89
  ch = range.detect { |_, r| r[:chapter] }
79
90
  @chapter = ch.last[:chapter] if ch
80
91
  [
81
- { book: @book.id, chapter: @chapter }.merge(range[:from]),
82
- { book: @book.id, chapter: @chapter }.merge(range[:to])
92
+ { book: book_id, chapter: @chapter }.merge(range[:from]),
93
+ { book: book_id, chapter: @chapter }.merge(range[:to])
83
94
  ]
84
95
  end
85
96
 
86
97
  def normalize_ref(ref)
87
98
  @chapter = ref[:chapter] if ref[:chapter]
88
99
  (1..2).map do
89
- { book: @book.id, chapter: @chapter }.merge(ref)
100
+ { book: book_id, chapter: @chapter }.merge(ref)
90
101
  end
91
102
  end
92
103
 
@@ -1,3 +1,3 @@
1
1
  module BibleRef
2
- VERSION = '0.2.1'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/bible_ref.rb CHANGED
@@ -1 +1,8 @@
1
1
  require_relative 'bible_ref/reference'
2
+
3
+ module BibleRef
4
+ module_function
5
+ def new(*args)
6
+ Reference.new(*args)
7
+ end
8
+ 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: 0.2.1
4
+ version: 1.0.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: 2014-07-07 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.1
41
55
  description: Bible reference parser returns normalized sets of ranges, ideal for querying
42
56
  a database or XML data source such as WEB in USFX.
43
57
  email: tim@timmorgan.org
@@ -47,7 +61,12 @@ extra_rdoc_files: []
47
61
  files:
48
62
  - README.md
49
63
  - lib/bible_ref.rb
50
- - lib/bible_ref/book.rb
64
+ - lib/bible_ref/canons.rb
65
+ - lib/bible_ref/canons/protestant.rb
66
+ - lib/bible_ref/languages.rb
67
+ - lib/bible_ref/languages/base.rb
68
+ - lib/bible_ref/languages/english.rb
69
+ - lib/bible_ref/languages/portuguese.rb
51
70
  - lib/bible_ref/parser.rb
52
71
  - lib/bible_ref/reference.rb
53
72
  - lib/bible_ref/version.rb
@@ -1,218 +0,0 @@
1
- module BibleRef
2
-
3
- class UnknownCanon < StandardError; end
4
-
5
- class Book
6
-
7
- CANONS = {
8
- protestant: %w(
9
- GEN EXO LEV NUM DEU JOS JDG RUT 1SA 2SA 1KI 2KI 1CH 2CH EZR NEH EST JOB PSA PRO ECC SNG ISA JER LAM EZK DAN HOS JOL AMO OBA JON MIC NAM HAB ZEP HAG ZEC MAL
10
- MAT MRK LUK JHN ACT ROM 1CO 2CO GAL EPH PHP COL 1TH 2TH 1TI 2TI TIT PHM HEB JAS 1PE 2PE 1JN 2JN 3JN JUD REV
11
- )
12
- }
13
-
14
- BOOKS = {
15
- 'GEN' => /^gen/,
16
- 'EXO' => /^ex/,
17
- 'LEV' => /^le?v/,
18
- 'NUM' => /^nu/,
19
- 'DEU' => /^de?ut/,
20
- 'JOS' => /^jos/,
21
- 'JDG' => /^ju?dg/,
22
- 'RUT' => /^ru/,
23
- '1SA' => /^1 sa?m/,
24
- '2SA' => /^2 sa?m/,
25
- '1KI' => /^1 (king|kgs)/,
26
- '2KI' => /^2 (king|kgs)/,
27
- '1CH' => /^1 chr/,
28
- '2CH' => /^2 chr/,
29
- 'EZR' => /^ez/,
30
- 'NEH' => /^ne/,
31
- 'EST' => /^est/,
32
- 'JOB' => /^jo?b/,
33
- 'PSA' => /^ps/,
34
- 'PRO' => /^pro?v/,
35
- 'ECC' => /^ecc/,
36
- 'SNG' => /^so?ng|^sol|^sg$/,
37
- 'ISA' => /^isa/,
38
- 'JER' => /^jer/,
39
- 'LAM' => /^lam/,
40
- 'EZK' => /^ez/,
41
- 'DAN' => /^dan/,
42
- 'HOS' => /^hos/,
43
- 'JOL' => /^joel/,
44
- 'AMO' => /^amo/,
45
- 'OBA' => /^ob/,
46
- 'JON' => /^jona/,
47
- 'MIC' => /^mi/,
48
- 'NAM' => /^nah/,
49
- 'HAB' => /^hab/,
50
- 'ZEP' => /^zep/,
51
- 'HAG' => /^hag/,
52
- 'ZEC' => /^zec/,
53
- 'MAL' => /^mal/,
54
- 'TOB' => /^tob/,
55
- 'JDT' => /^jud/,
56
- 'ESG' => /^est.*greek/,
57
- 'WIS' => /^wisdom/,
58
- 'SIR' => /^sir/,
59
- 'BAR' => /^bar/,
60
- 'LJE' => /^jeremy/,
61
- 'S3Y' => /^3 holy/,
62
- 'SUS' => /^sus/,
63
- 'BEL' => /^bel/,
64
- '1MA' => /^1 mac/,
65
- '2MA' => /^2 mac/,
66
- '1ES' => /^1 esd/,
67
- 'MAN' => /^prayer/,
68
- 'PS2' => /^psalm 151/,
69
- '3MA' => /^3 mac/,
70
- '2ES' => /^2 esd/,
71
- '4MA' => /^4 mac/,
72
- 'MAT' => /^mat/,
73
- 'MRK' => /^ma?rk/,
74
- 'LUK' => /^lu?k/,
75
- 'JHN' => /^john|^jn/,
76
- 'ACT' => /^act/,
77
- 'ROM' => /^rom/,
78
- '1CO' => /^1 cor/,
79
- '2CO' => /^2 cor/,
80
- 'GAL' => /^gal/,
81
- 'EPH' => /^eph/,
82
- 'PHP' => /^phil/,
83
- 'COL' => /^col/,
84
- '1TH' => /^1 the?s/,
85
- '2TH' => /^2 the?s/,
86
- '1TI' => /^1 tim/,
87
- '2TI' => /^2 tim/,
88
- 'TIT' => /^tit/,
89
- 'PHM' => /^phi?l/,
90
- 'HEB' => /^heb/,
91
- 'JAS' => /^jam/,
92
- '1PE' => /^1 pet/,
93
- '2PE' => /^2 pet/,
94
- '1JN' => /^1 jo?h?n/,
95
- '2JN' => /^2 jo?h?n/,
96
- '3JN' => /^3 jo?h?n/,
97
- 'JUD' => /^jud/,
98
- 'REV' => /^re?v/
99
- }
100
-
101
- FORMATTED_BOOKS = {
102
- 'GEN' => 'Genesis',
103
- 'EXO' => 'Exodus',
104
- 'LEV' => 'Leviticus',
105
- 'NUM' => 'Numbers',
106
- 'DEU' => 'Deuteronomy',
107
- 'JOS' => 'Joshua',
108
- 'JDG' => 'Judges',
109
- 'RUT' => 'Ruth',
110
- '1SA' => '1 Samuel',
111
- '2SA' => '2 Samuel',
112
- '1KI' => '1 Kings',
113
- '2KI' => '2 Kings',
114
- '1CH' => '1 Chronicles',
115
- '2CH' => '2 Chronicles',
116
- 'EZR' => 'Ezra',
117
- 'NEH' => 'Nehemiah',
118
- 'EST' => 'Esther',
119
- 'JOB' => 'Job',
120
- 'PSA' => 'Psalms',
121
- 'PRO' => 'Proverbs',
122
- 'ECC' => 'Ecclesiastes',
123
- 'SNG' => 'Song of Solomon',
124
- 'ISA' => 'Isaiah',
125
- 'JER' => 'Jeremiah',
126
- 'LAM' => 'Lamentations',
127
- 'EZK' => 'Ezekiel',
128
- 'DAN' => 'Daniel',
129
- 'HOS' => 'Hosea',
130
- 'JOL' => 'Joel',
131
- 'AMO' => 'Amos',
132
- 'OBA' => 'Obadiah',
133
- 'JON' => 'Jonah',
134
- 'MIC' => 'Micah',
135
- 'NAM' => 'Nahum',
136
- 'HAB' => 'Habakkuk',
137
- 'ZEP' => 'Zephaniah',
138
- 'HAG' => 'Haggai',
139
- 'ZEC' => 'Zechariah',
140
- 'MAL' => 'Malachi',
141
- 'TOB' => 'Tobit',
142
- 'JDT' => 'Judith',
143
- 'ESG' => 'Esther (Greek)',
144
- 'WIS' => 'Wisdom of Solomon',
145
- 'SIR' => 'Sirach',
146
- 'BAR' => 'Baruch',
147
- 'LJE' => 'Jeremy’s Letter',
148
- 'S3Y' => '3 Holy Children’s Song',
149
- 'SUS' => 'Susanna',
150
- 'BEL' => 'Bel and the Dragon',
151
- '1MA' => '1 Maccabees',
152
- '2MA' => '2 Maccabees',
153
- '1ES' => '1 Esdras',
154
- 'MAN' => 'Prayer of Manasses',
155
- 'PS2' => 'Psalm 151',
156
- '3MA' => '3 Maccabees',
157
- '2ES' => '2 Esdras',
158
- '4MA' => '4 Maccabees',
159
- 'MAT' => 'Matthew',
160
- 'MRK' => 'Mark',
161
- 'LUK' => 'Luke',
162
- 'JHN' => 'John',
163
- 'ACT' => 'Acts',
164
- 'ROM' => 'Romans',
165
- '1CO' => '1 Corinthians',
166
- '2CO' => '2 Corinthians',
167
- 'GAL' => 'Galatians',
168
- 'EPH' => 'Ephesians',
169
- 'PHP' => 'Philippians',
170
- 'COL' => 'Colossians',
171
- '1TH' => '1 Thessalonians',
172
- '2TH' => '2 Thessalonians',
173
- '1TI' => '1 Timothy',
174
- '2TI' => '2 Timothy',
175
- 'TIT' => 'Titus',
176
- 'PHM' => 'Philemon',
177
- 'HEB' => 'Hebrews',
178
- 'JAS' => 'James',
179
- '1PE' => '1 Peter',
180
- '2PE' => '2 Peter',
181
- '1JN' => '1 John',
182
- '2JN' => '2 John',
183
- '3JN' => '3 John',
184
- 'JUD' => 'Jude',
185
- 'REV' => 'Revelation'
186
- }
187
-
188
- def initialize(book, canon=:protestant)
189
- @canon = canon
190
- unless CANONS[@canon]
191
- raise UnknownCanon.new("#{canon} is not known. Canons this library support are: #{CANONS.join(', ')}")
192
- end
193
- @book = replace_roman_numerals(book).downcase
194
- end
195
-
196
- def id
197
- CANONS[@canon].each do |book|
198
- match = BOOKS[book]
199
- return book if @book =~ match
200
- end
201
- nil
202
- end
203
-
204
- def formatted
205
- FORMATTED_BOOKS[id]
206
- end
207
-
208
- private
209
-
210
- def replace_roman_numerals(book)
211
- book.sub!(/^iii/i, '3')
212
- book.sub!(/^ii/i, '2')
213
- book.sub!(/^i/i, '1')
214
- book
215
- end
216
-
217
- end
218
- end