scripref 2.0.0 → 2.1.0
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 +4 -4
- data/Changelog +3 -0
- data/Rakefile +3 -0
- data/lib/scripref/passage.rb +1 -1
- data/lib/scripref/sorter.rb +35 -2
- data/lib/scripref.rb +1 -1
- data/test/test_processor.rb +2 -2
- data/test/test_sorter.rb +75 -35
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1e8a5707b59a787a2c9d153d5664dc7089962afb7f301f381d340a54aa382fe2
|
|
4
|
+
data.tar.gz: 1b443da4486f615355a7eb98906228a6be744c1470396e731cb30c4ad4774189
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 91c1e585d9e956434b4806e227bd8bbc5dc1eaf1ca6f101966175bcedcdc3d4b071614c3b9e78e17ae3abc5437decc5b8e5d8978ee63a93247b923e255e71dad
|
|
7
|
+
data.tar.gz: 3715eee536614b2f359bd3e0ca5bf40e0d32d5d113881e1351002d91535829aa374f2115ac6f69b35e543e87e794b80fe826882fe40b41deb41cd0efd68882e4
|
data/Changelog
CHANGED
data/Rakefile
CHANGED
data/lib/scripref/passage.rb
CHANGED
data/lib/scripref/sorter.rb
CHANGED
|
@@ -23,7 +23,7 @@ module Scripref
|
|
|
23
23
|
module SortUpDown
|
|
24
24
|
def signum pass1, pass2
|
|
25
25
|
a, b = passage2arr(pass1), passage2arr(pass2)
|
|
26
|
-
a[0,
|
|
26
|
+
a[0, 4] + b[4, 4] <=> b[0, 4] + a[4, 4]
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -43,8 +43,41 @@ module Scripref
|
|
|
43
43
|
|
|
44
44
|
def passage2arr pass
|
|
45
45
|
b1 = book2num(pass.b1)
|
|
46
|
+
c1 = pass.c1 || 1
|
|
47
|
+
v1 = pass.v1 || 1
|
|
48
|
+
a1 = case pass.a1.to_s
|
|
49
|
+
when ''
|
|
50
|
+
0
|
|
51
|
+
when 'a'
|
|
52
|
+
1
|
|
53
|
+
when 'b'
|
|
54
|
+
2
|
|
55
|
+
when 'c'
|
|
56
|
+
3
|
|
57
|
+
end
|
|
46
58
|
b2 = book2num(pass.b2)
|
|
47
|
-
|
|
59
|
+
c2 = pass.c2 || Float::INFINITY
|
|
60
|
+
v2 = case pass.v2
|
|
61
|
+
when nil
|
|
62
|
+
Float::INFINITY
|
|
63
|
+
when Integer
|
|
64
|
+
pass.v2
|
|
65
|
+
when :f
|
|
66
|
+
pass.v1.to_i + 1
|
|
67
|
+
when :ff
|
|
68
|
+
pass.v1.to_i + 3
|
|
69
|
+
end
|
|
70
|
+
a2 = case pass.a2.to_s
|
|
71
|
+
when ''
|
|
72
|
+
0
|
|
73
|
+
when 'a'
|
|
74
|
+
-3
|
|
75
|
+
when 'b'
|
|
76
|
+
-2
|
|
77
|
+
when 'c'
|
|
78
|
+
-1
|
|
79
|
+
end
|
|
80
|
+
[b1, c1, v1, a1, b2, c2, v2, a2]
|
|
48
81
|
end
|
|
49
82
|
|
|
50
83
|
end
|
data/lib/scripref.rb
CHANGED
data/test/test_processor.rb
CHANGED
|
@@ -83,7 +83,7 @@ class TestProcessorVariousContexts < Test::Unit::TestCase
|
|
|
83
83
|
def test_verse_addon_or_postfix
|
|
84
84
|
text = 'Mt 1,1a'
|
|
85
85
|
processor = Processor.new(text, German)
|
|
86
|
-
ast = [[pass(text: text, b1: :Matt, c1: 1, v1: 1, b2: :Matt, c2: 1, v2: 1, a1:
|
|
86
|
+
ast = [[pass(text: text, b1: :Matt, c1: 1, v1: 1, b2: :Matt, c2: 1, v2: 1, a1: :a)]]
|
|
87
87
|
assert_equal ast, processor.each.to_a
|
|
88
88
|
text = 'Mt 1,1f'
|
|
89
89
|
processor = Processor.new(text, German)
|
|
@@ -98,7 +98,7 @@ class TestProcessorVariousContexts < Test::Unit::TestCase
|
|
|
98
98
|
def test_verse_addon_or_postfix_for_books_with_only_one_chapter
|
|
99
99
|
text = '2. Joh 5b'
|
|
100
100
|
processor = Processor.new(text, German)
|
|
101
|
-
ast = [[pass(text: text, b1: :'2John', c1: 1, v1: 5, b2: :'2John', c2: 1, v2: 5, a1:
|
|
101
|
+
ast = [[pass(text: text, b1: :'2John', c1: 1, v1: 5, b2: :'2John', c2: 1, v2: 5, a1: :b)]]
|
|
102
102
|
assert_equal ast, processor.each.to_a
|
|
103
103
|
text = '2. Joh 5f'
|
|
104
104
|
processor = Processor.new(text, German)
|
data/test/test_sorter.rb
CHANGED
|
@@ -3,46 +3,86 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative 'test_helper'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
include Scripref
|
|
9
|
-
include Test::Helper
|
|
10
|
-
|
|
11
|
-
def setup
|
|
12
|
-
@john_1 = pass(b1: :John, c1: 1, b2: :John, c2: 1)
|
|
13
|
-
@john_1_1_3 = pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3)
|
|
14
|
-
@john_1_1_18 = pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 18)
|
|
15
|
-
@john_2 = pass(b1: :John, c1: 2, b2: :John, c2: 2)
|
|
16
|
-
@heb_9 = pass(b1: :Heb, c1: 9, b2: :Heb, c2: 9)
|
|
17
|
-
@jas_1 = pass(b1: :Jas, c1: 1, b2: :Jas, c2: 1)
|
|
18
|
-
@pet_1 = pass(b1: :'1Pet', c1: 1, b2: :'1Pet', c2: 1)
|
|
19
|
-
end
|
|
6
|
+
module TestSorter
|
|
20
7
|
|
|
21
|
-
|
|
22
|
-
sorter = Sorter.new(Bookorder::Canonical)
|
|
23
|
-
assert_equal [@john_1, @heb_9, @jas_1, @pet_1], sorter.sort([@heb_9, @pet_1, @jas_1, @john_1])
|
|
24
|
-
assert_equal [@john_1_1_18, @john_1_1_3], sorter.sort([@john_1_1_3, @john_1_1_18])
|
|
25
|
-
assert_equal [@john_1, @john_1_1_18, @john_1_1_3, @john_2], sorter.sort([@john_1, @john_1_1_3, @john_2, @john_1_1_18])
|
|
26
|
-
end
|
|
8
|
+
class TestBookordering < Test::Unit::TestCase
|
|
27
9
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
include Scripref
|
|
11
|
+
include Test::Helper
|
|
12
|
+
|
|
13
|
+
def setup
|
|
14
|
+
@john_1 = pass(b1: :John, c1: 1, b2: :John, c2: 1)
|
|
15
|
+
@john_1_1_3 = pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3)
|
|
16
|
+
@john_1_1_18 = pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 18)
|
|
17
|
+
@john_2 = pass(b1: :John, c1: 2, b2: :John, c2: 2)
|
|
18
|
+
@heb_9 = pass(b1: :Heb, c1: 9, b2: :Heb, c2: 9)
|
|
19
|
+
@jas_1 = pass(b1: :Jas, c1: 1, b2: :Jas, c2: 1)
|
|
20
|
+
@pet_1 = pass(b1: :'1Pet', c1: 1, b2: :'1Pet', c2: 1)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_canonical_default
|
|
24
|
+
sorter = Sorter.new(Bookorder::Canonical)
|
|
25
|
+
assert_equal [@john_1, @heb_9, @jas_1, @pet_1], sorter.sort([@heb_9, @pet_1, @jas_1, @john_1])
|
|
26
|
+
assert_equal [@john_1_1_18, @john_1_1_3], sorter.sort([@john_1_1_3, @john_1_1_18])
|
|
27
|
+
assert_equal [@john_1, @john_1_1_18, @john_1_1_3, @john_2], sorter.sort([@john_1, @john_1_1_3, @john_2, @john_1_1_18])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_canonical_sort_up_up
|
|
31
|
+
sorter = Sorter.new(Bookorder::Canonical, Sorter::SortUpUp)
|
|
32
|
+
assert_equal [@john_1_1_3, @john_1_1_18], sorter.sort([@john_1_1_3, @john_1_1_18])
|
|
33
|
+
assert_equal [@john_1_1_3, @john_1_1_18, @john_1, @john_2], sorter.sort([@john_1, @john_1_1_3, @john_2, @john_1_1_18])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_luther_default
|
|
37
|
+
sorter = Sorter.new(Bookorder::Luther)
|
|
38
|
+
assert_equal [@john_1, @pet_1, @heb_9, @jas_1], sorter.sort([@heb_9, @pet_1, @jas_1, @john_1])
|
|
39
|
+
assert_equal [@john_1_1_18, @john_1_1_3], sorter.sort([@john_1_1_3, @john_1_1_18])
|
|
40
|
+
assert_equal [@john_1, @john_1_1_18, @john_1_1_3, @john_2], sorter.sort([@john_1, @john_1_1_3, @john_2, @john_1_1_18])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_luther_sort_up_up
|
|
44
|
+
sorter = Sorter.new(Bookorder::Luther, Sorter::SortUpUp)
|
|
45
|
+
assert_equal [@john_1, @pet_1, @heb_9, @jas_1], sorter.sort([@heb_9, @pet_1, @jas_1, @john_1])
|
|
46
|
+
assert_equal [@john_1_1_3, @john_1_1_18], sorter.sort([@john_1_1_3, @john_1_1_18])
|
|
47
|
+
assert_equal [@john_1_1_3, @john_1_1_18, @john_1, @john_2], sorter.sort([@john_1, @john_1_1_3, @john_2, @john_1_1_18])
|
|
48
|
+
end
|
|
33
49
|
|
|
34
|
-
def test_luther_default
|
|
35
|
-
sorter = Sorter.new(Bookorder::Luther)
|
|
36
|
-
assert_equal [@john_1, @pet_1, @heb_9, @jas_1], sorter.sort([@heb_9, @pet_1, @jas_1, @john_1])
|
|
37
|
-
assert_equal [@john_1_1_18, @john_1_1_3], sorter.sort([@john_1_1_3, @john_1_1_18])
|
|
38
|
-
assert_equal [@john_1, @john_1_1_18, @john_1_1_3, @john_2], sorter.sort([@john_1, @john_1_1_3, @john_2, @john_1_1_18])
|
|
39
50
|
end
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
class TestNumberordering < Test::Unit::TestCase
|
|
53
|
+
|
|
54
|
+
include Scripref
|
|
55
|
+
include Test::Helper
|
|
56
|
+
|
|
57
|
+
def setup
|
|
58
|
+
@sorter = Sorter.new(Bookorder::Canonical)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_sort_with_addons
|
|
62
|
+
f = Formatter.new(German, abbrev_level: 1)
|
|
63
|
+
ref = [
|
|
64
|
+
pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3),
|
|
65
|
+
pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a2: :b),
|
|
66
|
+
pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a2: :a),
|
|
67
|
+
pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a1: :a),
|
|
68
|
+
pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a1: :a, a2: :b),
|
|
69
|
+
pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a1: :a, a2: :a),
|
|
70
|
+
pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a1: :b)
|
|
71
|
+
]
|
|
72
|
+
assert_equal ref, @sorter.sort(ref)
|
|
73
|
+
assert_equal ref, @sorter.sort(ref.reverse)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_sort_with_addon_and_postfix
|
|
77
|
+
p = Parser.new(German)
|
|
78
|
+
pass1 = p.parse('Spr 25,6f').first
|
|
79
|
+
pass2 = p.parse('Spr 25,6b-7').first
|
|
80
|
+
assert_equal -1, @sorter.signum(pass1, pass2)
|
|
81
|
+
assert_equal 1, @sorter.signum(pass2, pass1)
|
|
82
|
+
assert_equal [pass1, pass2], @sorter.sort([pass1, pass2])
|
|
83
|
+
assert_equal [pass1, pass2], @sorter.sort([pass2, pass1])
|
|
84
|
+
end
|
|
85
|
+
|
|
46
86
|
end
|
|
47
87
|
|
|
48
88
|
end
|