scripref 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +5 -0
- data/Rakefile +1 -0
- data/lib/scripref/formatter.rb +4 -3
- data/lib/scripref/german.rb +1 -1
- data/lib/scripref/parser.rb +22 -12
- data/lib/scripref/pipelining.rb +19 -0
- data/lib/scripref.rb +6 -1
- data/test/test_english.rb +0 -1
- data/test/test_formatter.rb +2 -2
- data/test/test_parser.rb +11 -0
- data/test/test_pipelining.rb +28 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01a6a4eaf04a5db4c42caa6e28c39e4e024e6383
|
4
|
+
data.tar.gz: aaaf18868275f9e5c6e7c3cccfc139e9efe18dcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60f0173166dae8e8b133935eabbe99bfc624f819ab31a0b016876ec47104744bcaee0541e334eaab24e7129744c41c91e07c6e17164f809343208a418d6ca866
|
7
|
+
data.tar.gz: 954ee188ad98491e959db439801899dac9ae07af01072fb8fc1502065c5804e27537e452a965d65e67f46fd78aa4d0ffe804cc0ae0e82438e8edeaeb2aee0374
|
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
data/lib/scripref/formatter.rb
CHANGED
@@ -16,9 +16,8 @@ module Scripref
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
# Formats a reference (array of passages)
|
20
|
-
|
21
|
-
def fullref *reference
|
19
|
+
# Formats a reference (array of passages)
|
20
|
+
def format *reference
|
22
21
|
last_b = last_c = last_v = nil
|
23
22
|
pass_texts = reference.flatten.map do |pass|
|
24
23
|
changed = false
|
@@ -75,6 +74,8 @@ module Scripref
|
|
75
74
|
pass_texts.join(pass_separator)
|
76
75
|
end
|
77
76
|
|
77
|
+
alias << format
|
78
|
+
|
78
79
|
end
|
79
80
|
|
80
81
|
end
|
data/lib/scripref/german.rb
CHANGED
@@ -9,7 +9,7 @@ module Scripref
|
|
9
9
|
# Array of book names.
|
10
10
|
BOOK_NAMES = <<-END.strip.split(/,\s*/)
|
11
11
|
1. Mose, 2. Mose, 3. Mose, 4. Mose, 5. Mose, Josua, Richter, Ruth, 1. Samuel, 2. Samuel,
|
12
|
-
1. Könige, 2.Könige, 1. Chronika, 2. Chronika, Esra, Nehemia, Esther, Hiob, Psalm,
|
12
|
+
1. Könige, 2. Könige, 1. Chronika, 2. Chronika, Esra, Nehemia, Esther, Hiob, Psalm,
|
13
13
|
Sprüche, Prediger, Hohelied, Jesaja, Jeremia, Klagelieder, Hesekiel, Daniel, Hosea, Joel,
|
14
14
|
Amos, Obadja, Jona, Micha, Nahum, Habakuk, Zephanja, Haggai, Sacharja, Maleachi,
|
15
15
|
Matthäus, Markus, Lukas, Johannes, Apostelgeschichte, Römer, 1. Korinther, 2. Korinther,
|
data/lib/scripref/parser.rb
CHANGED
@@ -37,7 +37,7 @@ module Scripref
|
|
37
37
|
def b1
|
38
38
|
s = scan(book_re) or return nil
|
39
39
|
@text << s
|
40
|
-
@b1 = @b2 =
|
40
|
+
@b1 = @b2 = abbrev2num(s)
|
41
41
|
|
42
42
|
if check(Regexp.new(NUMBER_RE.source + cv_sep_re.source))
|
43
43
|
@c1 = @v1 = nil
|
@@ -107,7 +107,7 @@ module Scripref
|
|
107
107
|
def b2
|
108
108
|
s = scan(book_re) or return nil
|
109
109
|
@text << s
|
110
|
-
@b2 =
|
110
|
+
@b2 = abbrev2num(s)
|
111
111
|
@c2 = @v2 = nil
|
112
112
|
|
113
113
|
if check(Regexp.new(NUMBER_RE.source + cv_sep_re.source))
|
@@ -224,25 +224,35 @@ module Scripref
|
|
224
224
|
@a1 = @a2 = nil
|
225
225
|
end
|
226
226
|
|
227
|
+
def abbrev2num str
|
228
|
+
book2num(abbrev2book(str))
|
229
|
+
end
|
230
|
+
|
231
|
+
def abbrev2book str
|
232
|
+
@books_str ||= ('#' << book_names.join('#') << '#')
|
233
|
+
pattern = str.strip.chars.map {|c| Regexp.escape(c) << '[^#]*'}.join
|
234
|
+
re = /(?<=#)#{pattern}(?=#)/
|
235
|
+
names = @books_str.scan(re)
|
236
|
+
fail Error, format("Abbreviation %s is ambiguous it matches %s!", str, names.join(', ')) unless names.size == 1
|
237
|
+
names.first
|
238
|
+
end
|
239
|
+
|
227
240
|
def book2num str
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
num = i + 1
|
232
|
-
return num
|
233
|
-
end
|
241
|
+
unless @book2num
|
242
|
+
@book2num = {}
|
243
|
+
book_names.each_with_index {|s, i| @book2num[s] = i+1}
|
234
244
|
end
|
245
|
+
@book2num[str]
|
235
246
|
end
|
236
247
|
|
237
248
|
def inspect
|
238
249
|
"#<#{self.class} #{@mods.inspect}>"
|
239
250
|
end
|
240
251
|
|
241
|
-
|
252
|
+
alias << parse
|
253
|
+
|
254
|
+
class Error < RuntimeError; end
|
242
255
|
|
243
|
-
# check if the book has only one chapter
|
244
|
-
def self.book_has_only_one_chapter? book
|
245
|
-
[31, 63, 64, 65].include?(book)
|
246
256
|
end
|
247
257
|
|
248
258
|
end
|
data/lib/scripref.rb
CHANGED
@@ -7,7 +7,7 @@ require 'scripref/german'
|
|
7
7
|
|
8
8
|
module Scripref
|
9
9
|
|
10
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.5.0'
|
11
11
|
|
12
12
|
Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2) do
|
13
13
|
|
@@ -18,4 +18,9 @@ module Scripref
|
|
18
18
|
alias to_s text
|
19
19
|
end
|
20
20
|
|
21
|
+
# check if the book has only one chapter
|
22
|
+
def self.book_has_only_one_chapter? book
|
23
|
+
[31, 63, 64, 65].include?(book)
|
24
|
+
end
|
25
|
+
|
21
26
|
end
|
data/test/test_english.rb
CHANGED
data/test/test_formatter.rb
CHANGED
@@ -78,8 +78,8 @@ class TestFormatter < Test::Unit::TestCase
|
|
78
78
|
|
79
79
|
def check_formatting
|
80
80
|
ast = @parser.parse(@german)
|
81
|
-
assert_equal @german, @german_formatter.
|
82
|
-
assert_equal @english, @english_formatter.
|
81
|
+
assert_equal @german, @german_formatter.format(ast)
|
82
|
+
assert_equal @english, @english_formatter.format(ast)
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
data/test/test_parser.rb
CHANGED
@@ -16,6 +16,17 @@ class TestParser < Test::Unit::TestCase
|
|
16
16
|
assert_parsed_ast_for_text [pass(text, 8, nil, nil, 8, nil, nil)], text
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_ambiguous_book
|
20
|
+
assert_raises Scripref::Parser::Error do
|
21
|
+
begin
|
22
|
+
@parser.parse 'Jo'
|
23
|
+
rescue RuntimeError => e
|
24
|
+
assert_equal 'Abbreviation Jo is ambiguous it matches Josua, Joel, Jona, Johannes, Jakobus!', e.message
|
25
|
+
raise e
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
19
30
|
def test_book_and_chapter
|
20
31
|
text = 'Ruth 2'
|
21
32
|
assert_parsed_ast_for_text [pass(text, 8, 2, nil, 8, 2, nil)], text
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# - encoding: utf-8 -
|
2
|
+
require 'test/unit'
|
3
|
+
require 'test_helper'
|
4
|
+
require 'scripref'
|
5
|
+
|
6
|
+
class TestPipelining < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Test::Helper
|
9
|
+
include Scripref
|
10
|
+
|
11
|
+
def test_right_to_left
|
12
|
+
text = 'Hebräer 13,8'
|
13
|
+
parser = Parser.new(German)
|
14
|
+
formatter = Formatter.new(English)
|
15
|
+
result = formatter << (parser << text)
|
16
|
+
assert_equal 'Hebrews 13:8', result
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_left_to_right
|
20
|
+
require 'scripref/pipelining'
|
21
|
+
text = 'Hebräer 13,8'
|
22
|
+
parser = Parser.new(German)
|
23
|
+
formatter = Formatter.new(English)
|
24
|
+
result = text >> parser >> formatter
|
25
|
+
assert_equal 'Hebrews 13:8', result
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scripref
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Friedrich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rim
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: regtest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/scripref/formatter.rb
|
55
55
|
- lib/scripref/german.rb
|
56
56
|
- lib/scripref/parser.rb
|
57
|
+
- lib/scripref/pipelining.rb
|
57
58
|
- lib/scripref/processor.rb
|
58
59
|
- regtest/parser.rb
|
59
60
|
- test/test_english.rb
|
@@ -61,6 +62,7 @@ files:
|
|
61
62
|
- test/test_german.rb
|
62
63
|
- test/test_helper.rb
|
63
64
|
- test/test_parser.rb
|
65
|
+
- test/test_pipelining.rb
|
64
66
|
- test/test_processor.rb
|
65
67
|
homepage: http://gitorious.org/scripref
|
66
68
|
licenses: []
|