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 +4 -4
- data/.aspell.pws +3 -1
- data/Changelog +6 -0
- data/lib/scripref.rb +5 -2
- data/lib/scripref/basic_methods.rb +3 -1
- data/lib/scripref/bookname.rb +6 -4
- data/lib/scripref/bookorder.rb +20 -0
- data/lib/scripref/const_reader.rb +2 -1
- data/lib/scripref/english.rb +10 -6
- data/lib/scripref/formatter.rb +5 -4
- data/lib/scripref/german.rb +10 -6
- data/lib/scripref/include.rb +3 -1
- data/lib/scripref/parser.rb +17 -15
- data/lib/scripref/passage.rb +39 -45
- data/lib/scripref/pipelining.rb +2 -1
- data/lib/scripref/processor.rb +3 -2
- data/scripref.gemspec +3 -3
- data/test/test_bookname.rb +4 -2
- data/test/test_english.rb +16 -14
- data/test/test_formatter.rb +54 -52
- data/test/test_german.rb +12 -10
- data/test/test_helper.rb +3 -1
- data/test/test_integration.rb +3 -1
- data/test/test_parser.rb +66 -64
- data/test/test_passage.rb +7 -18
- data/test/test_pipelining.rb +3 -1
- data/test/test_processor.rb +20 -18
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e62a77dfe3ad29cd0a26f5321ca555364a9031e7f366509b6de98d2537fc3894
|
4
|
+
data.tar.gz: 2cea8d7e4c6bb09c74509f0a95a656e5d9bc4b5079fe8a47e24697c51804c1c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5ea83b84641277e5e01d04dc31e0381d66f547ef44117692713d23db8f880ee674db96458be0709776029be7b99ec913859675ba289096eed3689d11bdb352b
|
7
|
+
data.tar.gz: cde42713e59b183d3c605fe2cee0ce0667802b90dd79a115f538480053bb1b71eda0ba554c64b9772c58536dfd4ce2eb11b1e778e08877a556cba38e2afe73d7
|
data/.aspell.pws
CHANGED
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
|
-
#
|
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.
|
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'
|
data/lib/scripref/bookname.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
#
|
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
|
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
|
-
@
|
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
|
data/lib/scripref/english.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
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 =
|
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
|
77
|
-
def book_has_only_one_chapter?
|
78
|
-
[
|
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
|
data/lib/scripref/formatter.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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
|
31
|
-
def format_book
|
32
|
-
|
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
|
data/lib/scripref/german.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
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 =
|
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
|
77
|
-
def book_has_only_one_chapter?
|
78
|
-
[
|
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
|
data/lib/scripref/include.rb
CHANGED
data/lib/scripref/parser.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
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 =
|
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 =
|
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
|
242
|
+
def abbrev2osis_book_id str
|
241
243
|
s = str.strip
|
242
244
|
s.sub! /\.$/, ''
|
243
|
-
|
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|
|
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
|
262
|
-
unless @
|
263
|
-
@
|
264
|
-
book_names.
|
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
|
-
@
|
268
|
+
@str2osis_book_id[n] = bn.osis_id
|
267
269
|
end
|
268
270
|
bn.abbrevs.each do |n|
|
269
|
-
@
|
271
|
+
@str2osis_book_id[n] = bn.osis_id
|
270
272
|
end
|
271
273
|
end
|
272
274
|
end
|
273
275
|
end
|
274
276
|
|
275
|
-
def
|
276
|
-
|
277
|
-
@
|
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
|
data/lib/scripref/passage.rb
CHANGED
@@ -1,66 +1,27 @@
|
|
1
|
-
#
|
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.
|
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.
|
63
|
-
b = passage.
|
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
|
data/lib/scripref/pipelining.rb
CHANGED
data/lib/scripref/processor.rb
CHANGED
data/scripref.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: scripref 0.
|
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.
|
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"
|