scripref 1.2.2 → 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 +13 -0
- data/LICENSE +1 -1
- data/Rakefile +3 -0
- data/lib/scripref/basic_methods.rb +11 -5
- data/lib/scripref/bookname.rb +87 -9
- data/lib/scripref/bookorder.rb +36 -8
- data/lib/scripref/english.rb +76 -29
- data/lib/scripref/formatter.rb +7 -7
- data/lib/scripref/german.rb +76 -28
- data/lib/scripref/parser.rb +55 -54
- data/lib/scripref/passage.rb +4 -57
- data/lib/scripref/processor.rb +2 -0
- data/lib/scripref/sorter.rb +85 -0
- data/lib/scripref.rb +2 -1
- data/test/test_bookname.rb +13 -5
- data/test/test_english.rb +13 -13
- data/test/test_formatter.rb +3 -8
- data/test/test_german.rb +12 -12
- data/test/test_parser.rb +11 -0
- data/test/test_processor.rb +2 -2
- data/test/test_sorter.rb +88 -0
- metadata +3 -2
- data/test/test_passage.rb +0 -91
data/lib/scripref/parser.rb
CHANGED
|
@@ -6,7 +6,7 @@ require 'strscan'
|
|
|
6
6
|
|
|
7
7
|
module Scripref
|
|
8
8
|
|
|
9
|
-
class Parser
|
|
9
|
+
class Parser
|
|
10
10
|
|
|
11
11
|
attr_reader :error
|
|
12
12
|
|
|
@@ -21,12 +21,28 @@ module Scripref
|
|
|
21
21
|
# Parsing a string of a scripture reference
|
|
22
22
|
# @param str string to parse
|
|
23
23
|
def parse str
|
|
24
|
-
|
|
24
|
+
@scanner = StringScanner.new(str)
|
|
25
25
|
@result = []
|
|
26
26
|
@error = nil
|
|
27
27
|
start
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
def format_error
|
|
31
|
+
if error
|
|
32
|
+
format("%s\n%s\n%s^", error, @scanner.string, ' ' * @scanner.pointer)
|
|
33
|
+
else
|
|
34
|
+
''
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def inspect
|
|
39
|
+
"#<#{self.class} #{@mods.inspect}>"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
alias << parse
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
30
46
|
# start of parsing grammer
|
|
31
47
|
def start
|
|
32
48
|
@text = ''
|
|
@@ -35,14 +51,14 @@ module Scripref
|
|
|
35
51
|
|
|
36
52
|
# try to parse first book
|
|
37
53
|
def b1
|
|
38
|
-
s = scan(book_re) or return nil
|
|
54
|
+
s = @scanner.scan(book_re) or return nil
|
|
39
55
|
@text << s
|
|
40
|
-
@b1 = @b2 =
|
|
56
|
+
@b1 = @b2 = str2book_id(s)
|
|
41
57
|
@c1 = @v1 = @c2 = @v2 = nil
|
|
42
58
|
|
|
43
59
|
if pass_sep
|
|
44
60
|
b1 or give_up 'EOS or book expected!'
|
|
45
|
-
elsif check(Regexp.new(chapter_re.source + cv_sep_re.source))
|
|
61
|
+
elsif @scanner.check(Regexp.new(chapter_re.source + cv_sep_re.source))
|
|
46
62
|
@c1 = @v1 = nil
|
|
47
63
|
@c2 = @v2 = nil
|
|
48
64
|
c1
|
|
@@ -60,7 +76,7 @@ module Scripref
|
|
|
60
76
|
|
|
61
77
|
# try parse first chapter
|
|
62
78
|
def c1
|
|
63
|
-
s = scan(chapter_re) or return nil
|
|
79
|
+
s = @scanner.scan(chapter_re) or return nil
|
|
64
80
|
@text << s
|
|
65
81
|
@c1 = @c2 = s.to_i
|
|
66
82
|
@v1 = @v2 = nil
|
|
@@ -78,7 +94,7 @@ module Scripref
|
|
|
78
94
|
|
|
79
95
|
# try to parse first verse
|
|
80
96
|
def v1
|
|
81
|
-
s = scan(verse_re) or return nil
|
|
97
|
+
s = @scanner.scan(verse_re) or return nil
|
|
82
98
|
@text << s
|
|
83
99
|
@v1 = @v2 = s.to_i
|
|
84
100
|
|
|
@@ -92,7 +108,7 @@ module Scripref
|
|
|
92
108
|
|
|
93
109
|
if hyphen
|
|
94
110
|
b2 or (
|
|
95
|
-
if check(Regexp.new(chapter_re.source + cv_sep_re.source))
|
|
111
|
+
if @scanner.check(Regexp.new(chapter_re.source + cv_sep_re.source))
|
|
96
112
|
c2
|
|
97
113
|
else
|
|
98
114
|
v2 or give_up 'Chapter or verse expected!'
|
|
@@ -108,14 +124,14 @@ module Scripref
|
|
|
108
124
|
|
|
109
125
|
# try to parse second book
|
|
110
126
|
def b2
|
|
111
|
-
s = scan(book_re) or return nil
|
|
127
|
+
s = @scanner.scan(book_re) or return nil
|
|
112
128
|
@text << s
|
|
113
|
-
@b2 =
|
|
129
|
+
@b2 = str2book_id(s)
|
|
114
130
|
@c2 = @v2 = nil
|
|
115
131
|
|
|
116
132
|
if pass_sep
|
|
117
133
|
b1 or give_up 'EOS or book expected!'
|
|
118
|
-
elsif check(Regexp.new(chapter_re.source + cv_sep_re.source))
|
|
134
|
+
elsif @scanner.check(Regexp.new(chapter_re.source + cv_sep_re.source))
|
|
119
135
|
c2
|
|
120
136
|
else
|
|
121
137
|
if book_has_only_one_chapter?(@b2)
|
|
@@ -129,7 +145,7 @@ module Scripref
|
|
|
129
145
|
|
|
130
146
|
# try to parse second chapter
|
|
131
147
|
def c2
|
|
132
|
-
s = scan(chapter_re) or return nil
|
|
148
|
+
s = @scanner.scan(chapter_re) or return nil
|
|
133
149
|
@text << s
|
|
134
150
|
@c2 = s.to_i
|
|
135
151
|
|
|
@@ -144,7 +160,7 @@ module Scripref
|
|
|
144
160
|
|
|
145
161
|
# try to parse second verse
|
|
146
162
|
def v2
|
|
147
|
-
s = scan(verse_re) or return nil
|
|
163
|
+
s = @scanner.scan(verse_re) or return nil
|
|
148
164
|
@text << s
|
|
149
165
|
@v2 = s.to_i
|
|
150
166
|
|
|
@@ -163,16 +179,16 @@ module Scripref
|
|
|
163
179
|
|
|
164
180
|
# try to parse <tt>end of string</tt>
|
|
165
181
|
def epsilon
|
|
166
|
-
if eos?
|
|
182
|
+
if @scanner.eos?
|
|
167
183
|
push_passage
|
|
168
184
|
return @result
|
|
169
185
|
end
|
|
170
186
|
nil
|
|
171
187
|
end
|
|
172
188
|
|
|
173
|
-
# try to parse separator
|
|
189
|
+
# try to parse separator of chapter and verse
|
|
174
190
|
def cv_sep
|
|
175
|
-
if s = scan(cv_sep_re)
|
|
191
|
+
if s = @scanner.scan(cv_sep_re)
|
|
176
192
|
@text << s
|
|
177
193
|
s
|
|
178
194
|
else
|
|
@@ -182,7 +198,7 @@ module Scripref
|
|
|
182
198
|
|
|
183
199
|
# try to parse hyphen
|
|
184
200
|
def hyphen
|
|
185
|
-
if s = scan(hyphen_re)
|
|
201
|
+
if s = @scanner.scan(hyphen_re)
|
|
186
202
|
@text << s
|
|
187
203
|
s
|
|
188
204
|
else
|
|
@@ -192,7 +208,7 @@ module Scripref
|
|
|
192
208
|
|
|
193
209
|
# try to parse separator between passages
|
|
194
210
|
def pass_sep
|
|
195
|
-
if s = scan(pass_sep_re)
|
|
211
|
+
if s = @scanner.scan(pass_sep_re)
|
|
196
212
|
push_passage
|
|
197
213
|
@result << PassSep.new(s)
|
|
198
214
|
s
|
|
@@ -203,7 +219,7 @@ module Scripref
|
|
|
203
219
|
|
|
204
220
|
# try to parse verse separator
|
|
205
221
|
def verse_sep
|
|
206
|
-
if s = scan(verse_sep_re)
|
|
222
|
+
if s = @scanner.scan(verse_sep_re)
|
|
207
223
|
push_passage
|
|
208
224
|
@result << VerseSep.new(s)
|
|
209
225
|
s
|
|
@@ -214,7 +230,7 @@ module Scripref
|
|
|
214
230
|
|
|
215
231
|
# try to parse addons for verses
|
|
216
232
|
def verse_addon
|
|
217
|
-
if s = scan(verse_addon_re)
|
|
233
|
+
if s = @scanner.scan(verse_addon_re)
|
|
218
234
|
@text << s
|
|
219
235
|
s.to_sym
|
|
220
236
|
else
|
|
@@ -224,7 +240,7 @@ module Scripref
|
|
|
224
240
|
|
|
225
241
|
# try to parse postfixes for verse
|
|
226
242
|
def verse_postfix
|
|
227
|
-
s = (scan(postfix_one_following_verse_re) or scan(postfix_more_following_verses_re))
|
|
243
|
+
s = (@scanner.scan(postfix_one_following_verse_re) or @scanner.scan(postfix_more_following_verses_re))
|
|
228
244
|
if s
|
|
229
245
|
@text << s
|
|
230
246
|
s.to_sym
|
|
@@ -239,48 +255,43 @@ module Scripref
|
|
|
239
255
|
@a1 = @a2 = nil
|
|
240
256
|
end
|
|
241
257
|
|
|
242
|
-
def
|
|
258
|
+
def str2book_id str
|
|
243
259
|
s = str.strip
|
|
244
260
|
s.sub! /\.$/, ''
|
|
245
|
-
|
|
261
|
+
str2book_id_cache(s) or calculate_str2book_id(s)
|
|
246
262
|
end
|
|
247
263
|
|
|
248
|
-
def
|
|
264
|
+
def calculate_str2book_id str
|
|
249
265
|
s = str.strip
|
|
250
266
|
s.sub! /\.$/, ''
|
|
251
|
-
@books_str ||= ('#' <<
|
|
267
|
+
@books_str ||= ('#' << each_bookname.map(&:each_name).flat_map(&:to_a).join('#') << '#')
|
|
252
268
|
pattern = s.chars.map {|c| Regexp.escape(c) << '[^#]*'}.join
|
|
253
269
|
re = /(?<=#)#{pattern}(?=#)/
|
|
254
270
|
names = @books_str.scan(re)
|
|
255
|
-
uniq_numbers = names.map {|n|
|
|
271
|
+
uniq_numbers = names.map {|n| str2book_id_cache(n)}.uniq
|
|
256
272
|
if uniq_numbers.size != 1
|
|
257
|
-
unscan
|
|
273
|
+
@scanner.unscan
|
|
258
274
|
give_up format("Abbreviation %s is ambiguous it matches %s!", s, names.join(', '))
|
|
259
275
|
end
|
|
260
|
-
names.first
|
|
276
|
+
book_id = str2book_id_cache(names.first)
|
|
277
|
+
@str2book_id_cache[s] = book_id
|
|
278
|
+
book_id
|
|
261
279
|
end
|
|
262
280
|
|
|
263
|
-
def
|
|
264
|
-
unless @
|
|
265
|
-
@
|
|
266
|
-
|
|
267
|
-
bn.
|
|
268
|
-
@
|
|
269
|
-
end
|
|
270
|
-
bn.abbrevs.each do |n|
|
|
271
|
-
@str2osis_book_id[n] = bn.osis_id
|
|
281
|
+
def init_str2book_id_cache
|
|
282
|
+
unless @str2book_id_cache
|
|
283
|
+
@str2book_id_cache = {}
|
|
284
|
+
each_bookname do |bn|
|
|
285
|
+
bn.each_string do |s|
|
|
286
|
+
@str2book_id_cache[s] = bn.book_id
|
|
272
287
|
end
|
|
273
288
|
end
|
|
274
289
|
end
|
|
275
290
|
end
|
|
276
291
|
|
|
277
|
-
def
|
|
278
|
-
|
|
279
|
-
@
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
def inspect
|
|
283
|
-
"#<#{self.class} #{@mods.inspect}>"
|
|
292
|
+
def str2book_id_cache str
|
|
293
|
+
init_str2book_id_cache
|
|
294
|
+
@str2book_id_cache[str]
|
|
284
295
|
end
|
|
285
296
|
|
|
286
297
|
def give_up msg
|
|
@@ -288,16 +299,6 @@ module Scripref
|
|
|
288
299
|
fail ParserError, format_error
|
|
289
300
|
end
|
|
290
301
|
|
|
291
|
-
def format_error
|
|
292
|
-
if error
|
|
293
|
-
format("%s\n%s\n%s^", error, string, ' ' * pointer)
|
|
294
|
-
else
|
|
295
|
-
''
|
|
296
|
-
end
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
alias << parse
|
|
300
|
-
|
|
301
302
|
end
|
|
302
303
|
|
|
303
304
|
class ParserError < RuntimeError; end
|
data/lib/scripref/passage.rb
CHANGED
|
@@ -5,70 +5,17 @@ module Scripref
|
|
|
5
5
|
|
|
6
6
|
Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2, keyword_init: true) do
|
|
7
7
|
|
|
8
|
-
include Comparable
|
|
9
|
-
|
|
10
8
|
def to_a
|
|
11
|
-
[b1, c1, v1, b2, c2, v2]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def <=> other
|
|
15
|
-
return unless other.kind_of? Passage
|
|
16
|
-
self.to_numeric_array <=> other.to_numeric_array
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Returns true if the instance and the given passage overlap.
|
|
20
|
-
# That means both has at least one verse in common.
|
|
21
|
-
def overlap? passage
|
|
22
|
-
fail ArgumentError, 'value must be a passage' unless passage.kind_of? Passage
|
|
23
|
-
a = self.to_numeric_array
|
|
24
|
-
b = passage.to_numeric_array
|
|
25
|
-
[a[0..2] <=> b[3..5], b[0..2] <=> a[3..5]].max < 1
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Returns an array of b1, c1, v1
|
|
29
|
-
def start
|
|
30
|
-
[b1, c1, v1]
|
|
9
|
+
[b1, c1, v1, a1, b2, c2, v2, a2]
|
|
31
10
|
end
|
|
32
11
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
end
|
|
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]
|
|
12
|
+
def == other
|
|
13
|
+
return false unless other.kind_of? Passage
|
|
14
|
+
to_a == other.to_a
|
|
52
15
|
end
|
|
53
16
|
|
|
54
17
|
alias to_s text
|
|
55
18
|
|
|
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
|
-
|
|
72
19
|
end
|
|
73
20
|
|
|
74
21
|
end
|
data/lib/scripref/processor.rb
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Scripref
|
|
5
|
+
|
|
6
|
+
class Sorter
|
|
7
|
+
|
|
8
|
+
def initialize *mods
|
|
9
|
+
@mods = mods
|
|
10
|
+
mods.each {|m| extend m}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def sort *references
|
|
14
|
+
passages = references.flatten.select {|e| e.kind_of? Scripref::Passage}
|
|
15
|
+
passages.sort do |p1, p2|
|
|
16
|
+
signum(p1, p2)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
alias << sort
|
|
21
|
+
|
|
22
|
+
# Mixin to sort ascending by start verse and desending by end verse of passages
|
|
23
|
+
module SortUpDown
|
|
24
|
+
def signum pass1, pass2
|
|
25
|
+
a, b = passage2arr(pass1), passage2arr(pass2)
|
|
26
|
+
a[0, 4] + b[4, 4] <=> b[0, 4] + a[4, 4]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Mixin to sort ascending by start verse and ascending by end verse of passages
|
|
31
|
+
module SortUpUp
|
|
32
|
+
def signum pass1, pass2
|
|
33
|
+
a, b = passage2arr(pass1), passage2arr(pass2)
|
|
34
|
+
a <=> b
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Default sorting
|
|
39
|
+
|
|
40
|
+
include SortUpDown
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def passage2arr pass
|
|
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
|
|
58
|
+
b2 = book2num(pass.b2)
|
|
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]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
data/lib/scripref.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'delegate'
|
|
|
5
5
|
|
|
6
6
|
module Scripref
|
|
7
7
|
|
|
8
|
-
VERSION = '1.
|
|
8
|
+
VERSION = '2.1.0'
|
|
9
9
|
|
|
10
10
|
require_relative 'scripref/bookname'
|
|
11
11
|
require_relative 'scripref/bookorder'
|
|
@@ -15,6 +15,7 @@ module Scripref
|
|
|
15
15
|
require_relative 'scripref/parser'
|
|
16
16
|
require_relative 'scripref/passage'
|
|
17
17
|
require_relative 'scripref/processor'
|
|
18
|
+
require_relative 'scripref/sorter'
|
|
18
19
|
|
|
19
20
|
class Token < DelegateClass(String)
|
|
20
21
|
def initialize *args
|
data/test/test_bookname.rb
CHANGED
|
@@ -8,15 +8,23 @@ class TestBookname < Test::Unit::TestCase
|
|
|
8
8
|
include Scripref
|
|
9
9
|
|
|
10
10
|
def setup
|
|
11
|
-
@zef = Bookname.new(
|
|
11
|
+
@zef = Bookname.new(book_id: :Zeph, name: 'Zefanja', abbrevs: %w(Zefan Zef), alternatives: Bookname.new(book_id: :Zeph, name: 'Zephanja', abbrevs: 'Zeph'))
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def
|
|
15
|
-
assert_equal
|
|
14
|
+
def test_each_name
|
|
15
|
+
assert_equal %w(Zefanja Zephanja), @zef.each_name.to_a
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def
|
|
19
|
-
assert_equal
|
|
18
|
+
def test_each_string
|
|
19
|
+
assert_equal %w(Zefanja Zefan Zef Zephanja Zeph), @zef.each_string.to_a
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_parse
|
|
23
|
+
assert_equal @zef, Bookname.parse('Zeph: Zefanja|Zefan|Zef, Zephanja|Zeph')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_dump
|
|
27
|
+
assert_equal 'Zeph: Zefanja|Zefan|Zef, Zephanja|Zeph', @zef.dump
|
|
20
28
|
end
|
|
21
29
|
|
|
22
30
|
end
|
data/test/test_english.rb
CHANGED
|
@@ -13,7 +13,7 @@ class TestEnglish < Test::Unit::TestCase
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def test_size_of_book_array
|
|
16
|
-
assert_equal 66, English::
|
|
16
|
+
assert_equal 66, English::BOOKNAMES_HASH.size
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def test_book_re
|
|
@@ -32,20 +32,20 @@ class TestEnglish < Test::Unit::TestCase
|
|
|
32
32
|
assert_match book_re, 'Rev'
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
def
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
def test_book2book_id
|
|
36
|
+
assert_book_id :Gen, 'Genesis'
|
|
37
|
+
assert_book_id :Matt, 'Matthew'
|
|
38
|
+
assert_book_id :Rev, 'Revelation'
|
|
39
|
+
assert_book_id :Gen, 'Gen'
|
|
40
|
+
assert_book_id :Gen, 'Ge'
|
|
41
|
+
assert_book_id :'2Tim', '2 Tim'
|
|
42
|
+
assert_book_id :'2Tim', '2Tim'
|
|
43
|
+
assert_book_id :'2Tim', '2Tm'
|
|
44
|
+
assert_book_id :Matt, 'Mat'
|
|
45
|
+
assert_book_id :Rev, 'Rev'
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
def
|
|
48
|
+
def assert_book_id id, str
|
|
49
49
|
assert_equal id, @parser.parse(str).first.b1
|
|
50
50
|
end
|
|
51
51
|
|
data/test/test_formatter.rb
CHANGED
|
@@ -170,7 +170,8 @@ class TestFormatter < Test::Unit::TestCase
|
|
|
170
170
|
|
|
171
171
|
def test_two_refs_with_book_with_only_one_chapter
|
|
172
172
|
text = 'Obadja 3.5'
|
|
173
|
-
|
|
173
|
+
t1, t2 = text.split(dot)
|
|
174
|
+
assert_formated_text_for_ast text, [pass(text: t1, b1: :Obad, c1: 1, v1: 3, b2: :Obad, c2: 1, v2: 3), dot, pass(text: t2, b1: :Obad, c1: 1, v1: 5, b2: :Obad, c2: 1, v2: 5)]
|
|
174
175
|
end
|
|
175
176
|
|
|
176
177
|
######################################################################
|
|
@@ -261,18 +262,12 @@ class TestFormatter < Test::Unit::TestCase
|
|
|
261
262
|
######################################################################
|
|
262
263
|
|
|
263
264
|
def test_formatting_with_book_abbrevs
|
|
264
|
-
@german_formatter.
|
|
265
|
+
@german_formatter.abbrev_level = 1
|
|
265
266
|
text = 'Mat 3,4; Mar; Joh 3,16'
|
|
266
267
|
t1, t2, t3 = text.split(semi)
|
|
267
268
|
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: :Mark, b2: :Mark), semi, pass(text: t3, b1: :John, c1: 3, v1: 16, b2: :John, c2: 3, v2: 16)]
|
|
268
269
|
end
|
|
269
270
|
|
|
270
|
-
def test_exception_for_unhandled_bookformat
|
|
271
|
-
assert_raise NoMethodError do
|
|
272
|
-
@german_formatter.bookformat = :unknown
|
|
273
|
-
@german_formatter.format [pass(text: 1, b1: :Exod, c1: 3, v1: 4, b2: :Deut, c2: 6, v2: 7)]
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
271
|
private
|
|
277
272
|
|
|
278
273
|
def assert_formated_text_for_ast text, ast
|
data/test/test_german.rb
CHANGED
|
@@ -13,7 +13,7 @@ class TestGerman < Test::Unit::TestCase
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def test_size_of_book_array
|
|
16
|
-
assert_equal 66, German::
|
|
16
|
+
assert_equal 66, German::BOOKNAMES_HASH.size
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def test_book_re
|
|
@@ -32,19 +32,19 @@ class TestGerman < Test::Unit::TestCase
|
|
|
32
32
|
assert_match book_re, 'Off'
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
def
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
def test_book2book_id
|
|
36
|
+
assert_book_id :Gen, '1. Mose'
|
|
37
|
+
assert_book_id :Matt, 'Matthäus'
|
|
38
|
+
assert_book_id :Rev, 'Offenbarung'
|
|
39
|
+
assert_book_id :Gen, '1. Mo'
|
|
40
|
+
assert_book_id :Gen, '1.Mo'
|
|
41
|
+
assert_book_id :Gen, '1M'
|
|
42
|
+
assert_book_id :Matt, 'Mat'
|
|
43
|
+
assert_book_id :Phil, 'Phil'
|
|
44
|
+
assert_book_id :Rev, 'Off'
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
def
|
|
47
|
+
def assert_book_id id, str
|
|
48
48
|
@parser ||= Scripref::Parser.new(Scripref::German)
|
|
49
49
|
assert_equal id, @parser.parse(str).first.b1
|
|
50
50
|
end
|
data/test/test_parser.rb
CHANGED
|
@@ -333,6 +333,17 @@ class TestParser < Test::Unit::TestCase
|
|
|
333
333
|
assert_parsed_ast_for_text [pass(text: text, b1: :Ps, c1: 23, v1: 6, b2: :Ps, c2: 23, v2: 6)], text
|
|
334
334
|
end
|
|
335
335
|
|
|
336
|
+
def test_alternatives
|
|
337
|
+
# In German Zephanja is alternative name for Zefanja
|
|
338
|
+
a = pass(b1: :Zeph, c1: 2, b2: :Zeph, c2: 2).to_a
|
|
339
|
+
assert_equal a, @parser.parse('Zefanja 2').first.to_a
|
|
340
|
+
assert_equal a, @parser.parse('Zefa 2').first.to_a
|
|
341
|
+
assert_equal a, @parser.parse('Zef 2').first.to_a
|
|
342
|
+
assert_equal a, @parser.parse('Zephanja 2').first.to_a
|
|
343
|
+
assert_equal a, @parser.parse('Zepha 2').first.to_a
|
|
344
|
+
assert_equal a, @parser.parse('Zeph 2').first.to_a
|
|
345
|
+
end
|
|
346
|
+
|
|
336
347
|
private
|
|
337
348
|
|
|
338
349
|
def assert_equal_passage expected, actual
|
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)
|