scripref 0.15.0 → 1.1.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: 9424ceb062e9f3a2aa526c65f567b0bcf701c50fef3179f62e3ebe379cbae657
4
- data.tar.gz: 6743fc2a2e22cadc78ab32a58ae0886e9f99d72ae8e53c1902130b81b72f3cbf
3
+ metadata.gz: 18851c425f1c4a9504ede784a43a46d80a668c9059bc000d6f866b6ce3a5ffe2
4
+ data.tar.gz: e7cdaa42c34785fd755dc747247ea100ca757c9fed062cca691060c8c5288c3b
5
5
  SHA512:
6
- metadata.gz: 6213a3eafeacb7f56ae929f7d09b083e9eaffd92b09115492cebfd2b343761dac77899d2e2d2394a4e84c72a82ae60abf84811eee5f32a5fdfcfa1a068089265
7
- data.tar.gz: 820bb49d040ca7b05c9a6367f6f30b0aeb09737362a3303ce498c306b98ac4015e6e7e25817666a33cefd674a21d8d4522cb74816a20942c00df8a699d5548bb
6
+ metadata.gz: 01c5874544e15524587022c02e5e3002fa170f07889248f1937410671f94e03db239ec8fd5cfd47db8dee687c7b41b9ba56a4fb8fd12ebffb6f050b3a64eb2c3
7
+ data.tar.gz: 1745d52b620f5b71e9f12627a9b797f668f160e914de8869ab05c692218b87567aa08ff4eae6b2d04e9cad36dd43c1d868d5c8ac4f4b47cfcfeb19e41eea1063
data/Changelog CHANGED
@@ -1,3 +1,12 @@
1
+ 1.1.0
2
+ Adapt German abbreviations.
3
+
4
+ 1.0.0
5
+ Major release with following two incompatible changes:
6
+ Use OSIS abbreviations for books.
7
+ Remove Passage#+ and Passage#-. This methods seems not to be so useful.
8
+ Further a new module Bookorder is introduced.
9
+
1
10
  0.15.0
2
11
  Add some more abbreviations for German book names.
3
12
 
data/Rakefile CHANGED
@@ -2,19 +2,9 @@ require 'rim/tire'
2
2
  require 'rim/regtest'
3
3
  require 'rim/version'
4
4
 
5
- $:.unshift File.dirname(__FILE__) + '/lib'
6
- require 'scripref'
7
-
8
5
  Rim.setup do
9
- name 'scripref'
10
- authors 'Jan Friedrich'
11
- email 'janfri26@gmail.com'
12
- homepage 'https://github.com/janfri/scripref'
13
- version Scripref::VERSION
14
- summary 'Library for parsing scripture references in real texts.'
15
6
  if feature_loaded? 'rim/irb'
16
7
  irb_requires %w(scripref scripref/include scripref/pipelining)
17
8
  end
18
- ruby_version '>=2.5.0'
19
9
  test_warning false
20
10
  end
@@ -1,4 +1,6 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: false
3
+
2
4
  module Scripref
3
5
 
4
6
  # Mixin with methods of basic functionality
@@ -1,12 +1,14 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Scripref
4
5
 
5
6
  class Bookname
6
7
 
7
- attr_reader :names, :abbrevs
8
+ attr_reader :osis_id, :names, :abbrevs
8
9
 
9
- def initialize names, abbrevs
10
+ def initialize osis_id:, names:, abbrevs:
11
+ @osis_id = osis_id
10
12
  @names = Array(names)
11
13
  @abbrevs = Array(abbrevs)
12
14
  end
@@ -20,7 +22,7 @@ module Scripref
20
22
  end
21
23
 
22
24
  def to_s
23
- @names.first
25
+ @osis_id
24
26
  end
25
27
 
26
28
  alias to_str to_s
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Scripref
5
+
6
+ # Constants of different orderings of bible books using standardized IDs
7
+ # (see https://wiki.crosswire.org/OSIS_Book_Abbreviations)
8
+ module Bookorder
9
+
10
+ # Canonical order (the default order without any apocryphal books)
11
+ CANONICAL = %i[
12
+ Gen Exod Lev Num Deut Josh Judg Ruth 1Sam 2Sam 1Kgs 2Kgs 1Chr 2Chr Ezra
13
+ Neh Esth Job Ps Prov Eccl Song Isa Jer Lam Ezek Dan Hos Joel Amos Obad
14
+ Jonah Mic Nah Hab Zeph Hag Zech Mal Matt Mark Luke John Acts Rom 1Cor
15
+ 2Cor Gal Eph Phil Col 1Thess 2Thess 1Tim 2Tim Titus Phlm Heb Jas 1Pet
16
+ 2Pet 1John 2John 3John Jude Rev
17
+ ]
18
+ end
19
+
20
+ end
@@ -1,4 +1,5 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: false
2
3
 
3
4
  # Mixin to generate instance methods to access of mixin constants.
4
5
  #
@@ -1,5 +1,6 @@
1
- # - encoding: utf-8 -
2
- require 'scripref/bookname'
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
3
4
  require 'scripref/const_reader'
4
5
 
5
6
  module Scripref
@@ -31,7 +32,10 @@ module Scripref
31
32
  END
32
33
 
33
34
  # Array of book names.
34
- BOOK_NAMES = book_names.zip(book_abbrevs).map {|name, abbrev| Bookname.new(name, abbrev)}
35
+ BOOK_NAMES = Bookorder::CANONICAL.zip(book_names, book_abbrevs).map {|osis_book_id, names, abbrevs| Bookname.new(osis_id: osis_book_id, names: names, abbrevs: abbrevs)}
36
+
37
+ # Map of OSIS book ID to instance of Bookname
38
+ OSIS_BOOK_ID_TO_BOOK_NAME = Bookorder::CANONICAL.zip(BOOK_NAMES).map {|id, n| [id, n]}.to_h
35
39
 
36
40
  # Separator between chapter and verse.
37
41
  CV_SEPARATOR = ':'
@@ -73,9 +77,9 @@ module Scripref
73
77
  POSTFIX_MORE_FOLLOWING_VERSES_RE = /ff\b\s*/o
74
78
 
75
79
  # Check if book has only one chapter
76
- # @param book book as number
77
- def book_has_only_one_chapter? book
78
- [31, 57, 63, 64, 65].include?(book)
80
+ # @param osis_id OSIS-ID of the book
81
+ def book_has_only_one_chapter? osis_id
82
+ %i[Obad Phlm 2John 3John Jude].include?(osis_id)
79
83
  end
80
84
 
81
85
  # Regular expression to match punctuation marks
@@ -1,4 +1,5 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Scripref
4
5
 
@@ -27,9 +28,9 @@ module Scripref
27
28
  end
28
29
 
29
30
  # Formats a book
30
- # @param num number of book (starting at 1)
31
- def format_book num
32
- book_names[num - 1].send @bookformat
31
+ # @param osis_book_id OSIS-ID for book
32
+ def format_book osis_book_id
33
+ osis_book_id_to_book_name[osis_book_id].send @bookformat
33
34
  end
34
35
 
35
36
  # Formats a chapter
@@ -1,5 +1,6 @@
1
- # - encoding: utf-8 -
2
- require 'scripref/bookname'
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
3
4
  require 'scripref/const_reader'
4
5
 
5
6
  module Scripref
@@ -19,19 +20,22 @@ module Scripref
19
20
  END
20
21
 
21
22
  book_abbrevs = <<-END.strip.split(/,\s*/).map {|e| e.split('|')}
22
- 1.Mo|1Mo|1M, 2.Mo|2Mo|2M, 3.Mo|3Mo|3M, 4.Mo|4Mo|4M, 5.Mo|5Mo|5M, Jos, Ri,
23
- Ruth, 1.Sam|1Sam|1Sm, 2.Sam|2Sam|2Sm, 1.Kön|1Kön|1Kö, 2.Kön|2Kön|2Kö,
24
- 1.Chr|1Chr|1Ch, 2.Chr|2Chr|2Ch, Esr, Neh, Est, Hi, Ps, Spr, Pred,
23
+ 1. Mos|1Mo|1M, 2. Mos|2Mo|2M, 3. Mos|3Mo|3M, 4. Mos|4Mo|4M, 5. Mos|5Mo|5M, Jos, Ri,
24
+ Ruth, 1. Sam|1Sam|1Sm, 2. Sam|2Sam|2Sm, 1. Kön|1Kön|1Kö, 2. Kön|2Kön|2Kö,
25
+ 1. Chr|1Chr|1Ch, 2. Chr|2Chr|2Ch, Esr, Neh, Est, Hi, Ps, Spr, Pred,
25
26
  Hohel|Hoh|Hl, Jes, Jer, Klag, Hes, Dan, Hos, Joel, Amos|Am, Obad|Ob,
26
27
  Jona|Jon, Mich|Mi, Nah, Hab, Zef, Hag, Sach, Mal, Mat|Mt, Mar|Mr, Luk|Lk,
27
- Joh|Jh, Apg, Röm|Rö, 1.Ko|1Ko, 2.Ko|2Ko, Gal, Eph, Phil, Kol,
28
- 1.Thes|1Thes|1Th, 2.Thes|2Thes|2Th, 1.Tim, 2.Tim, Tit, Philem|Phm, Heb,
29
- Jak, 1.Pet|1Pet|1Pe, 2.Pet|2Pet|2Pe, 1.Joh|1Joh|1Jo, 2.Joh|2Joh|2Jo,
30
- 3.Joh|3Joh|3Jo, Jud, Off
28
+ Joh|Jh, Apg, Röm|Rö, 1. Kor|1Ko, 2. Kor|2Ko, Gal, Eph, Phil, Kol,
29
+ 1. Thes|1Thes|1Th, 2. Thes|2Thes|2Th, 1. Tim|1Tim, 2. Tim|2Tim, Tit, Philem|Phm, Heb,
30
+ Jak, 1. Pet|1Pet|1Pe, 2. Pet|2Pet|2Pe, 1. Joh|1Joh|1Jo, 2. Joh|2Joh|2Jo,
31
+ 3. Joh|3Joh|3Jo, Jud, Off
31
32
  END
32
33
 
33
34
  # Array of book names.
34
- BOOK_NAMES = book_names.zip(book_abbrevs).map {|name, abbrev| Bookname.new(name, abbrev)}
35
+ BOOK_NAMES = Bookorder::CANONICAL.zip(book_names, book_abbrevs).map {|osis_book_id, names, abbrevs| Bookname.new(osis_id: osis_book_id, names: names, abbrevs: abbrevs)}
36
+
37
+ # Map of OSIS book ID to instance of Bookname
38
+ OSIS_BOOK_ID_TO_BOOK_NAME = Bookorder::CANONICAL.zip(BOOK_NAMES).map {|id, n| [id, n]}.to_h
35
39
 
36
40
  # Separator between chapter and verse.
37
41
  CV_SEPARATOR = ','
@@ -73,9 +77,9 @@ module Scripref
73
77
  POSTFIX_MORE_FOLLOWING_VERSES_RE = /ff\b\s*/o
74
78
 
75
79
  # Check if book has only one chapter
76
- # @param book book as number
77
- def book_has_only_one_chapter? book
78
- [31, 57, 63, 64, 65].include?(book)
80
+ # @param osis_id OSIS-ID of the book
81
+ def book_has_only_one_chapter? osis_id
82
+ %i[Obad Phlm 2John 3John Jude].include?(osis_id)
79
83
  end
80
84
 
81
85
  # Regular expression to match punctuation marks
@@ -1,4 +1,6 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'scripref'
3
5
 
4
6
  include Scripref
@@ -1,4 +1,6 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: false
3
+
2
4
  require 'scripref/basic_methods'
3
5
  require 'strscan'
4
6
 
@@ -35,7 +37,7 @@ module Scripref
35
37
  def b1
36
38
  s = scan(book_re) or return nil
37
39
  @text << s
38
- @b1 = @b2 = abbrev2num(s)
40
+ @b1 = @b2 = abbrev2osis_book_id(s)
39
41
  @c1 = @v1 = @c2 = @v2 = nil
40
42
 
41
43
  if pass_sep
@@ -108,7 +110,7 @@ module Scripref
108
110
  def b2
109
111
  s = scan(book_re) or return nil
110
112
  @text << s
111
- @b2 = abbrev2num(s)
113
+ @b2 = abbrev2osis_book_id(s)
112
114
  @c2 = @v2 = nil
113
115
 
114
116
  if pass_sep
@@ -237,10 +239,10 @@ module Scripref
237
239
  @a1 = @a2 = nil
238
240
  end
239
241
 
240
- def abbrev2num str
242
+ def abbrev2osis_book_id str
241
243
  s = str.strip
242
244
  s.sub! /\.$/, ''
243
- str2book_num(s) or str2book_num(abbrev2book(s))
245
+ str2osis_book_id(s) or str2osis_book_id(abbrev2book(s))
244
246
  end
245
247
 
246
248
  def abbrev2book str
@@ -250,7 +252,7 @@ module Scripref
250
252
  pattern = s.chars.map {|c| Regexp.escape(c) << '[^#]*'}.join
251
253
  re = /(?<=#)#{pattern}(?=#)/
252
254
  names = @books_str.scan(re)
253
- uniq_numbers = names.map {|n| str2book_num(n)}.uniq
255
+ uniq_numbers = names.map {|n| str2osis_book_id(n)}.uniq
254
256
  if uniq_numbers.size != 1
255
257
  unscan
256
258
  give_up format("Abbreviation %s is ambiguous it matches %s!", s, names.join(', '))
@@ -258,23 +260,23 @@ module Scripref
258
260
  names.first
259
261
  end
260
262
 
261
- def init_str2book_num
262
- unless @str2book_num
263
- @str2book_num = {}
264
- book_names.each_with_index do |bn, i|
263
+ def init_str2osis_book_id
264
+ unless @str2osis_book_id
265
+ @str2osis_book_id = {}
266
+ book_names.each do |bn|
265
267
  bn.names.each do |n|
266
- @str2book_num[n] = i+1
268
+ @str2osis_book_id[n] = bn.osis_id
267
269
  end
268
270
  bn.abbrevs.each do |n|
269
- @str2book_num[n] = i+1
271
+ @str2osis_book_id[n] = bn.osis_id
270
272
  end
271
273
  end
272
274
  end
273
275
  end
274
276
 
275
- def str2book_num str
276
- init_str2book_num
277
- @str2book_num[str]
277
+ def str2osis_book_id str
278
+ init_str2osis_book_id
279
+ @str2osis_book_id[str]
278
280
  end
279
281
 
280
282
  def inspect
@@ -1,66 +1,27 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  module Scripref
3
5
 
4
6
  Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2, keyword_init: true) do
5
7
 
6
8
  include Comparable
7
9
 
8
- def + other
9
- to_a.zip(other.to_a).map {|a, b| a + b}
10
- end
11
-
12
- def - other
13
- to_a.zip(other.to_a).map {|a, b| b - a}
14
- end
15
-
16
10
  def to_a
17
11
  [b1, c1, v1, b2, c2, v2]
18
12
  end
19
13
 
20
14
  def <=> other
21
15
  return unless other.kind_of? Passage
22
- self.make_comparable.to_a <=> other.make_comparable.to_a
23
- end
24
-
25
- # Returns a copy which is comparable, that means
26
- # all values are numeric.
27
- # This is a heuristic approach.
28
- def make_comparable max: 999, ff: 3
29
- self.dup.make_comparable! max: max, ff: ff
30
- end
31
-
32
- # Makes the Passage instance comparable, that means
33
- # all values are numeric.
34
- # This is a heuristic approach.
35
- def make_comparable! max: 999, ff: 3
36
- self.b1 ||= 1
37
- self.c1 ||= 1
38
- self.v1 ||= 1
39
- self.b2 ||= max
40
- self.c2 ||= max
41
- self.v2 ||= max
42
- if self.v2 == :f
43
- self.v2 = self.v1 + 1
44
- end
45
- if self.v2 == :ff
46
- self.v2 = self.v1 + ff
47
- end
48
- self
49
- end
50
-
51
- # Checks if the instance is comparable, that means
52
- # all values are numeric and so the <=> method
53
- # can be applied.
54
- def comparable?
55
- to_a.map {|e| Numeric === e}.uniq == [true]
16
+ self.to_numeric_array <=> other.to_numeric_array
56
17
  end
57
18
 
58
19
  # Returns true if the instance and the given passage overlap.
59
20
  # That means both has at least one verse in common.
60
21
  def overlap? passage
61
22
  fail ArgumentError, 'value must be a passage' unless passage.kind_of? Passage
62
- a = self.make_comparable.to_a
63
- b = passage.make_comparable.to_a
23
+ a = self.to_numeric_array
24
+ b = passage.to_numeric_array
64
25
  [a[0..2] <=> b[3..5], b[0..2] <=> a[3..5]].max < 1
65
26
  end
66
27
 
@@ -74,7 +35,40 @@ module Scripref
74
35
  [b2, c2, v2]
75
36
  end
76
37
 
38
+ def to_numeric_array max: 999, ff: 3
39
+ _b1 = Passage.book_id2num[b1]
40
+ _c1 = c1 || 1
41
+ _v1 = v1 || 1
42
+ _b2 = Passage.book_id2num[b2]
43
+ _c2 = c2 || max
44
+ _v2 = v2 || max
45
+ if _v2 == :f
46
+ _v2 = _v1 + 1
47
+ end
48
+ if _v2 == :ff
49
+ _v2 = _v1 + ff
50
+ end
51
+ [_b1, _c1, _v1, _b2, _c2, _v2]
52
+ end
53
+
77
54
  alias to_s text
55
+
56
+ @book_id2num = {}
57
+ osis_book_ids = %i[
58
+ Gen Exod Lev Num Deut Josh Judg Ruth 1Sam 2Sam 1Kgs 2Kgs 1Chr 2Chr Ezra
59
+ Neh Esth Job Ps Prov Eccl Song Isa Jer Lam Ezek Dan Hos Joel Amos Obad
60
+ Jonah Mic Nah Hab Zeph Hag Zech Mal Matt Mark Luke John Acts Rom 1Cor
61
+ 2Cor Gal Eph Phil Col 1Thess 2Thess 1Tim 2Tim Titus Phlm Heb Jas 1Pet
62
+ 2Pet 1John 2John 3John Jude Rev
63
+ ]
64
+ osis_book_ids.each_with_index do |book_id, i|
65
+ @book_id2num[book_id] = i+1
66
+ end
67
+
68
+ class << self
69
+ attr_reader :book_id2num
70
+ end
71
+
78
72
  end
79
73
 
80
74
  end
@@ -1,4 +1,5 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Scripref
4
5
 
@@ -1,7 +1,8 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'strscan'
3
5
  require 'scripref/basic_methods'
4
- require 'scripref/parser'
5
6
 
6
7
  module Scripref
7
8
 
data/lib/scripref.rb CHANGED
@@ -1,11 +1,14 @@
1
- # - encoding: utf-8 -
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'delegate'
3
5
 
4
6
  module Scripref
5
7
 
6
- VERSION = '0.15.0'
8
+ VERSION = '1.1.0'
7
9
 
8
10
  autoload :Bookname, 'scripref/bookname'
11
+ autoload :Bookorder, 'scripref/bookorder'
9
12
  autoload :English, 'scripref/english'
10
13
  autoload :Formatter, 'scripref/formatter'
11
14
  autoload :German, 'scripref/german'
data/regtest/formatter.rb CHANGED
@@ -5,10 +5,10 @@ require 'scripref'
5
5
  include Scripref
6
6
 
7
7
  o = OpenStruct.new
8
- o.b1 = [42]
8
+ o.b1 = [:Luke]
9
9
  o.c1 = [1, nil]
10
10
  o.v1 = [2, nil]
11
- o.b2 = [43, nil]
11
+ o.b2 = [:John, nil]
12
12
  o.c2 = [3, nil]
13
13
  o.v2 = [4, nil]
14
14