scripref 0.12.0 → 0.13.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 +5 -5
- data/.aspell.pws +22 -0
- data/Changelog +9 -0
- data/Rakefile +1 -0
- data/lib/scripref/english.rb +3 -0
- data/lib/scripref/german.rb +3 -0
- data/lib/scripref/parser.rb +4 -2
- data/lib/scripref/passage.rb +1 -5
- data/lib/scripref/processor.rb +23 -16
- data/lib/scripref.rb +1 -1
- data/regtest/formatter.rb +3 -5
- data/regtest/parser.rb +1 -2
- data/regtest/processor.rb +1 -2
- data/regtest/processor.yml +194 -169
- data/scripref.gemspec +37 -0
- data/test/test_formatter.rb +51 -51
- data/test/test_helper.rb +2 -2
- data/test/test_parser.rb +76 -68
- data/test/test_passage.rb +6 -6
- data/test/test_processor.rb +47 -18
- metadata +24 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa9e6be87d748d3bd5a78a583cd7cffe7785548debe997f15478da1d19454b2d
|
4
|
+
data.tar.gz: c1cd0125bf8fdee4befaf21409746f1f71bbcc7931e67d91f4abfb68d67dd624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 813b10551e8a03e2c8cf0419316372a304d080b987adaaa0f5fe8e8ab80edb67c150a49abeea26db81a10a8b6e72f7a873674ff4773ac3368cb5c1c5d03007a2
|
7
|
+
data.tar.gz: a336bb178df986af14dc04e90619680c9853dd8e12433cd0b6c070486d3a565e50394c3d069421eb1d5a2db82974b0da8cea70016525c48da09825453e4619df
|
data/.aspell.pws
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
personal_ws-1.1 en 21
|
2
|
+
Bookname
|
3
|
+
ParserError
|
4
|
+
PassSep
|
5
|
+
Philipper
|
6
|
+
Psalmen
|
7
|
+
Psm
|
8
|
+
Scripref
|
9
|
+
VerseSep
|
10
|
+
addons
|
11
|
+
autoload
|
12
|
+
formatter
|
13
|
+
fullref
|
14
|
+
mixins
|
15
|
+
pipelining
|
16
|
+
postfix
|
17
|
+
postfixes
|
18
|
+
refactoring
|
19
|
+
refactorings
|
20
|
+
regtest
|
21
|
+
sep
|
22
|
+
struct
|
data/Changelog
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
0.13.0
|
2
|
+
Use keyword arguments for Passage.
|
3
|
+
Adapt regular expression to match multiple lines.
|
4
|
+
New approach to handle punctuation marks in processor: use explicit regular
|
5
|
+
expression.
|
6
|
+
Allow parsing of abbrevs which matches more spellings of the same book (e.g.
|
7
|
+
Psm -> Psalm/Psalmen in German).
|
8
|
+
A lot of other improvements for corner cases.
|
9
|
+
|
1
10
|
0.12.0
|
2
11
|
Allow periods at the end of book abbreviations.
|
3
12
|
|
data/Rakefile
CHANGED
data/lib/scripref/english.rb
CHANGED
data/lib/scripref/german.rb
CHANGED
data/lib/scripref/parser.rb
CHANGED
@@ -232,13 +232,14 @@ module Scripref
|
|
232
232
|
end
|
233
233
|
|
234
234
|
def push_passage
|
235
|
-
@result << Passage.new(@text, @b1, @c1, @v1, @b2, @c2, @v2, a1: @a1, a2: @a2)
|
235
|
+
@result << Passage.new(text: @text, b1: @b1, c1: @c1, v1: @v1, b2: @b2, c2: @c2, v2: @v2, a1: @a1, a2: @a2)
|
236
236
|
@text = ''
|
237
237
|
@a1 = @a2 = nil
|
238
238
|
end
|
239
239
|
|
240
240
|
def abbrev2num str
|
241
241
|
s = str.strip
|
242
|
+
s.sub! /\.$/, ''
|
242
243
|
str2book_num(s) or str2book_num(abbrev2book(s))
|
243
244
|
end
|
244
245
|
|
@@ -249,7 +250,8 @@ module Scripref
|
|
249
250
|
pattern = s.chars.map {|c| Regexp.escape(c) << '[^#]*'}.join
|
250
251
|
re = /(?<=#)#{pattern}(?=#)/
|
251
252
|
names = @books_str.scan(re)
|
252
|
-
|
253
|
+
uniq_numbers = names.map {|n| str2book_num(n)}.uniq
|
254
|
+
if uniq_numbers.size != 1
|
253
255
|
unscan
|
254
256
|
give_up format("Abbreviation %s is ambiguous it matches %s!", s, names.join(', '))
|
255
257
|
end
|
data/lib/scripref/passage.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
# - encoding: utf-8 -
|
2
2
|
module Scripref
|
3
3
|
|
4
|
-
Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2) do
|
4
|
+
Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2, keyword_init: true) do
|
5
5
|
|
6
6
|
include Comparable
|
7
7
|
|
8
|
-
def initialize text, b1, c1, v1, b2, c2, v2, a1: nil, a2: nil
|
9
|
-
super text, b1, c1, v1, b2, c2, v2, a1, a2
|
10
|
-
end
|
11
|
-
|
12
8
|
def + other
|
13
9
|
to_a.zip(other.to_a).map {|a, b| a + b}
|
14
10
|
end
|
data/lib/scripref/processor.rb
CHANGED
@@ -26,8 +26,9 @@ module Scripref
|
|
26
26
|
def each_ref
|
27
27
|
if block_given?
|
28
28
|
scanner = StringScanner.new(text)
|
29
|
-
while scanner.
|
30
|
-
|
29
|
+
while scanner.scan(/(.*?)(#{reference_re.source})/m)
|
30
|
+
_, ref = fix_scanner_and_results(scanner)
|
31
|
+
yield @parser.parse(ref)
|
31
32
|
end
|
32
33
|
self
|
33
34
|
else
|
@@ -40,9 +41,10 @@ module Scripref
|
|
40
41
|
def each
|
41
42
|
if block_given?
|
42
43
|
scanner = StringScanner.new(text)
|
43
|
-
while scanner.scan(/(.*?)(#{reference_re.source})/)
|
44
|
-
|
45
|
-
yield
|
44
|
+
while scanner.scan(/(.*?)(#{reference_re.source})/m)
|
45
|
+
text, ref = fix_scanner_and_results(scanner)
|
46
|
+
yield text unless text.empty?
|
47
|
+
yield @parser.parse(ref)
|
46
48
|
end
|
47
49
|
yield scanner.rest if scanner.rest?
|
48
50
|
self
|
@@ -55,25 +57,30 @@ module Scripref
|
|
55
57
|
"#<#{self.class} #{@mods.inspect}>"
|
56
58
|
end
|
57
59
|
|
58
|
-
# private
|
59
|
-
|
60
60
|
# Regular expression to heuristically identify a reference
|
61
61
|
def reference_re
|
62
62
|
return @reference_re if @reference_re
|
63
|
-
verse_with_optional_addon_or_postfix =
|
63
|
+
verse_with_optional_addon_or_postfix =
|
64
|
+
[verse_re, '(', postfix_one_following_verse_re, '|', postfix_more_following_verses_re, '|', verse_addon_re, ')?']
|
64
65
|
re_parts = [
|
65
|
-
|
66
|
-
|
67
|
-
'(', book_re, ')'
|
68
|
-
'|',
|
69
|
-
verse_with_optional_addon_or_postfix,
|
70
|
-
'|',
|
71
|
-
'(', [chapter_re, cv_sep_re, verse_re, verse_sep_re, hyphen_re, pass_sep_re].map(&:source).join(')|('), ')',
|
72
|
-
')*'
|
66
|
+
'(', book_re, ')', '(', verse_with_optional_addon_or_postfix, '|', chapter_re, ')',
|
67
|
+
# more than one passage
|
68
|
+
'(', verse_with_optional_addon_or_postfix, '|', Regexp.union(cv_sep_re, verse_sep_re, hyphen_re, pass_sep_re, book_re, chapter_re), ')*'
|
73
69
|
].map {|e| Regexp === e ? e.source : e}
|
74
70
|
@reference_re = Regexp.compile(re_parts.join, nil)
|
75
71
|
end
|
76
72
|
|
73
|
+
def fix_scanner_and_results scanner
|
74
|
+
text = scanner[1]
|
75
|
+
ref = scanner[2]
|
76
|
+
re = /#{punctuation_marks_re.source}$/
|
77
|
+
if ref =~ re
|
78
|
+
scanner.pos -= $&.size
|
79
|
+
ref.sub! re, ''
|
80
|
+
end
|
81
|
+
[text, ref]
|
82
|
+
end
|
83
|
+
|
77
84
|
end
|
78
85
|
|
79
86
|
end
|
data/lib/scripref.rb
CHANGED
data/regtest/formatter.rb
CHANGED
@@ -2,7 +2,6 @@ require 'ostruct'
|
|
2
2
|
require 'regtest'
|
3
3
|
require 'scripref'
|
4
4
|
|
5
|
-
include Regtest
|
6
5
|
include Scripref
|
7
6
|
|
8
7
|
o = OpenStruct.new
|
@@ -15,12 +14,11 @@ o.v2 = [4, nil]
|
|
15
14
|
|
16
15
|
formatter = Formatter.new(German)
|
17
16
|
|
18
|
-
combinations(o).each do |c|
|
19
|
-
|
20
|
-
pass = Passage.new('', *a)
|
17
|
+
Regtest.combinations(o).each do |c|
|
18
|
+
pass = Passage.new(text: '', b1: c.b1, c1: c.c1, v1: c.v1, b2: c.b2, c2: c.c2, v2: c.v2)
|
21
19
|
h = pass.to_h
|
22
20
|
h.shift
|
23
|
-
sample h do
|
21
|
+
Regtest.sample h do
|
24
22
|
formatter.format([pass])
|
25
23
|
end
|
26
24
|
end
|
data/regtest/parser.rb
CHANGED