scripref 0.15.0 → 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
  SHA256:
3
- metadata.gz: 9424ceb062e9f3a2aa526c65f567b0bcf701c50fef3179f62e3ebe379cbae657
4
- data.tar.gz: 6743fc2a2e22cadc78ab32a58ae0886e9f99d72ae8e53c1902130b81b72f3cbf
3
+ metadata.gz: e62a77dfe3ad29cd0a26f5321ca555364a9031e7f366509b6de98d2537fc3894
4
+ data.tar.gz: 2cea8d7e4c6bb09c74509f0a95a656e5d9bc4b5079fe8a47e24697c51804c1c2
5
5
  SHA512:
6
- metadata.gz: 6213a3eafeacb7f56ae929f7d09b083e9eaffd92b09115492cebfd2b343761dac77899d2e2d2394a4e84c72a82ae60abf84811eee5f32a5fdfcfa1a068089265
7
- data.tar.gz: 820bb49d040ca7b05c9a6367f6f30b0aeb09737362a3303ce498c306b98ac4015e6e7e25817666a33cefd674a21d8d4522cb74816a20942c00df8a699d5548bb
6
+ metadata.gz: e5ea83b84641277e5e01d04dc31e0381d66f547ef44117692713d23db8f880ee674db96458be0709776029be7b99ec913859675ba289096eed3689d11bdb352b
7
+ data.tar.gz: cde42713e59b183d3c605fe2cee0ce0667802b90dd79a115f538480053bb1b71eda0ba554c64b9772c58536dfd4ce2eb11b1e778e08877a556cba38e2afe73d7
data/.aspell.pws CHANGED
@@ -1,5 +1,7 @@
1
- personal_ws-1.1 en 21
1
+ personal_ws-1.1 en 23
2
2
  Bookname
3
+ Bookorder
4
+ OSIS
3
5
  ParserError
4
6
  PassSep
5
7
  Philipper
data/Changelog CHANGED
@@ -1,3 +1,9 @@
1
+ 1.0.0
2
+ Major release with following two incompatible changes:
3
+ Use OSIS abbreviations for books.
4
+ Remove Passage#+ and Passage#-. This methods seems not to be so useful.
5
+ Further a new module Bookorder is introduced.
6
+
1
7
  0.15.0
2
8
  Add some more abbreviations for German book names.
3
9
 
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.0.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'
@@ -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
@@ -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,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/scripref.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: scripref 0.15.0 ruby lib
2
+ # stub: scripref 1.0.0 ruby lib
3
3
  #
4
4
  # This file is automatically generated by rim.
5
5
  # PLEASE DO NOT EDIT IT DIRECTLY!
@@ -7,7 +7,7 @@
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "scripref"
10
- s.version = "0.15.0"
10
+ s.version = "1.0.0"
11
11
 
12
12
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.date = "2020-05-22"
16
16
  s.description = ""
17
17
  s.email = "janfri26@gmail.com"
18
- s.files = ["./.aspell.pws", "Changelog", "LICENSE", "README.md", "Rakefile", "lib/scripref", "lib/scripref.rb", "lib/scripref/basic_methods.rb", "lib/scripref/bookname.rb", "lib/scripref/const_reader.rb", "lib/scripref/english.rb", "lib/scripref/formatter.rb", "lib/scripref/german.rb", "lib/scripref/include.rb", "lib/scripref/parser.rb", "lib/scripref/passage.rb", "lib/scripref/pipelining.rb", "lib/scripref/processor.rb", "regtest/formatter.rb", "regtest/formatter.yml", "regtest/parser.rb", "regtest/parser.yml", "regtest/processor.rb", "regtest/processor.yml", "scripref.gemspec", "test/test_bookname.rb", "test/test_english.rb", "test/test_formatter.rb", "test/test_german.rb", "test/test_helper.rb", "test/test_integration.rb", "test/test_parser.rb", "test/test_passage.rb", "test/test_pipelining.rb", "test/test_processor.rb"]
18
+ s.files = ["./.aspell.pws", "Changelog", "LICENSE", "README.md", "Rakefile", "lib/scripref", "lib/scripref.rb", "lib/scripref/basic_methods.rb", "lib/scripref/bookname.rb", "lib/scripref/bookorder.rb", "lib/scripref/const_reader.rb", "lib/scripref/english.rb", "lib/scripref/formatter.rb", "lib/scripref/german.rb", "lib/scripref/include.rb", "lib/scripref/parser.rb", "lib/scripref/passage.rb", "lib/scripref/pipelining.rb", "lib/scripref/processor.rb", "regtest/formatter.rb", "regtest/formatter.yml", "regtest/parser.rb", "regtest/parser.yml", "regtest/processor.rb", "regtest/processor.yml", "scripref.gemspec", "test/test_bookname.rb", "test/test_english.rb", "test/test_formatter.rb", "test/test_german.rb", "test/test_helper.rb", "test/test_integration.rb", "test/test_parser.rb", "test/test_passage.rb", "test/test_pipelining.rb", "test/test_processor.rb"]
19
19
  s.homepage = "https://github.com/janfri/scripref"
20
20
  s.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
21
21
  s.rubygems_version = "3.1.2"