scripref 2.0.0 → 2.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41762855bac59cfd4181dacab1ae3cb5d5fa879e08e841d60d9fbde5170a5f65
4
- data.tar.gz: debe69c84f21f2d0af4e5ba88ddd8a0ee89c78ca449a4dc0ee302c593ecb46a0
3
+ metadata.gz: 1b86988fd1527cd91715024994bc47a03f0b564a74c5ebf11781e00a7a9ebe82
4
+ data.tar.gz: cf809a65188207a7688dfe150af32d90acb038a871c93e9e250e8a200945f68c
5
5
  SHA512:
6
- metadata.gz: 40877991379c9c1d743fa68575fdc2de3d8f16984483e0b121aa306913f18f5c06af30cc0fee604ea8c2d9678989811388a8c2e12980a74ee7a390051da56345
7
- data.tar.gz: b80cdba6be11573f7691913d8415a0c45874996e6050ef4f6fd91535006ffcffb2cdaa4e714b5ede4649b617abfb6a795c73b3b2d655420786fe78c574eec2f5
6
+ metadata.gz: b00eee0bf3b0126a320f1908e2312e4fbe86c99fa504ffc598fa709d887bc51fff6ecb140a16f25dc8897276f2717c28baa738e35dbb9869c31c2d44953154f9
7
+ data.tar.gz: aec528ec46bb8e7470c7ef06fac6411d4c36ccf3e3595541d07a611309a545e91404eb28c8de8e3189039a2b4be7ff04e437c023f170163a2558433a72f3bee6
data/Changelog CHANGED
@@ -1,3 +1,9 @@
1
+ 2.1.1
2
+ Use the verse separator between addon and verse when formatting.
3
+
4
+ 2.1.0
5
+ Implement correct sorting for passages with addons.
6
+
1
7
  2.0.0
2
8
  Major release with following breaking changes:
3
9
  Rewrite Bookorder and Bookname and adapt Formatter#format accordingly.
data/Rakefile CHANGED
@@ -5,6 +5,9 @@ require 'rim/version'
5
5
  Rim.setup do
6
6
  if feature_loaded? 'rim/irb'
7
7
  irb_requires %w(scripref scripref/include scripref/pipelining)
8
+ if File.exist?(fn = './.irb_init.rb')
9
+ irb_requires << fn
10
+ end
8
11
  end
9
12
  test_warning false
10
13
  end
@@ -103,7 +103,7 @@ module Scripref
103
103
  if v1 && (@changed || @last_v != v1)
104
104
  if ! book_has_only_one_chapter?(@pass.b1)
105
105
  case last_token
106
- when Verse
106
+ when Verse, Addon
107
107
  push_sep verse_separator
108
108
  when Token
109
109
  push_sep cv_separator
@@ -6,7 +6,7 @@ module Scripref
6
6
  Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2, keyword_init: true) do
7
7
 
8
8
  def to_a
9
- [b1, c1, v1, b2, c2, v2]
9
+ [b1, c1, v1, a1, b2, c2, v2, a2]
10
10
  end
11
11
 
12
12
  def == other
@@ -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, 3] + b[3, 3] <=> b[0, 3] + a[3, 3]
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
- [b1, pass.c1 || 1, pass.v1 || 1, b2, pass.c2 || Float::INFINITY, pass.v2 || Float::INFINITY]
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
@@ -5,7 +5,7 @@ require 'delegate'
5
5
 
6
6
  module Scripref
7
7
 
8
- VERSION = '2.0.0'
8
+ VERSION = '2.1.1'
9
9
 
10
10
  require_relative 'scripref/bookname'
11
11
  require_relative 'scripref/bookorder'
@@ -238,6 +238,21 @@ class TestFormatter < Test::Unit::TestCase
238
238
  assert_formated_text_for_ast text, [pass(text: t1, b1: :Matt, c1: 3, v1: 4, b2: :Matt, c2: 3, v2: 4), semi, pass(text: t2, b1: :Matt, c1: 8, b2: :Matt, c2: 8), semi, pass(text: t3, b1: :John, c1: 3, v1: 16, b2: :John, c2: 3, v2: 16)]
239
239
  end
240
240
 
241
+ def test_verse_after_addon
242
+ text = 'Johannes 1,1-3.1-3a.1-3b.1a-3.1b-3.1a-3a.1a-3b'
243
+ ast = [
244
+ pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3), dot,
245
+ pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a2: :a), dot,
246
+ pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a2: :b), dot,
247
+ pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a1: :a), dot,
248
+ pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a1: :b), dot,
249
+ pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a1: :a, a2: :a), dot,
250
+ pass(b1: :John, c1: 1, v1: 1, b2: :John, c2: 1, v2: 3, a1: :a, a2: :b)
251
+ ]
252
+ assert_formated_text_for_ast text, ast
253
+ end
254
+
255
+
241
256
  ######################################################################
242
257
  # complex variants of references
243
258
  ######################################################################
@@ -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: 'a')]]
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: 'b')]]
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
- class TestSorter < Test::Unit::TestCase
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
- def test_canonical_default
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
- def test_canonical_sort_up_up
29
- sorter = Sorter.new(Bookorder::Canonical, Sorter::SortUpUp)
30
- assert_equal [@john_1_1_3, @john_1_1_18], sorter.sort([@john_1_1_3, @john_1_1_18])
31
- 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])
32
- end
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
- def test_luther_sort_up_up
42
- sorter = Sorter.new(Bookorder::Luther, Sorter::SortUpUp)
43
- assert_equal [@john_1, @pet_1, @heb_9, @jas_1], sorter.sort([@heb_9, @pet_1, @jas_1, @john_1])
44
- assert_equal [@john_1_1_3, @john_1_1_18], sorter.sort([@john_1_1_3, @john_1_1_18])
45
- 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])
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scripref
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich