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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d474cd23788d8e7fba5f76d10c0dae60e205000e
4
- data.tar.gz: f2ca72e4fd6bb01e0d48d2b177e469cc1db5bad6
3
+ metadata.gz: 01a6a4eaf04a5db4c42caa6e28c39e4e024e6383
4
+ data.tar.gz: aaaf18868275f9e5c6e7c3cccfc139e9efe18dcb
5
5
  SHA512:
6
- metadata.gz: 46913ffca73f184d92fbc33d2d02f311a8e456575cd229cd3d6cd05ee63a989c04d2102118afa00cf9562ce79bd6e84904b770a747952e3951fd1a672915c725
7
- data.tar.gz: bcb8a59ae40f73e66fcc2676c6fe50fd2ddc02dd60fbd29291e6541516d0432a46b0af6e8aad2a43f59eca45ba567db5b8828b034998c0a114ba9f1d01b8c683
6
+ metadata.gz: 60f0173166dae8e8b133935eabbe99bfc624f819ab31a0b016876ec47104744bcaee0541e334eaab24e7129744c41c91e07c6e17164f809343208a418d6ca866
7
+ data.tar.gz: 954ee188ad98491e959db439801899dac9ae07af01072fb8fc1502065c5804e27537e452a965d65e67f46fd78aa4d0ffe804cc0ae0e82438e8edeaeb2aee0374
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 0.5.0
2
+ Rename Formatter#fullref -> #format.
3
+ Implementing pipelining with >>.
4
+ Fix typo in German book names.
5
+
1
6
  0.4.0
2
7
  Handling books with only one chapter correct.
3
8
 
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rim/tire'
2
2
  require 'rim/regtest'
3
+ require 'rim/version'
3
4
 
4
5
  $:.unshift File.dirname(__FILE__) + '/lib'
5
6
  require 'scripref'
@@ -16,9 +16,8 @@ module Scripref
16
16
  end
17
17
  end
18
18
 
19
- # Formats a reference (array of passages) with full
20
- # book names (i.e. Hebrews 3:8)
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
@@ -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,
@@ -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 = book2num(s)
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 = book2num(s)
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
- return nil unless book_re =~str
229
- books_res.each_with_index do |re, i|
230
- if str =~ Regexp.new('^' << re.to_s << '$')
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
- end
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
@@ -0,0 +1,19 @@
1
+ # - encoding: utf-8 -
2
+
3
+ module Scripref
4
+
5
+ module Pipelining
6
+ def >> o
7
+ o << self
8
+ end
9
+ end
10
+
11
+ end
12
+
13
+ class Array
14
+ include Scripref::Pipelining
15
+ end
16
+
17
+ class String
18
+ include Scripref::Pipelining
19
+ end
data/lib/scripref.rb CHANGED
@@ -7,7 +7,7 @@ require 'scripref/german'
7
7
 
8
8
  module Scripref
9
9
 
10
- VERSION = '0.4.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
@@ -29,7 +29,6 @@ class TestEnglish < Test::Unit::TestCase
29
29
  assert_book_num 66, 'Revelation'
30
30
  assert_book_num 1, 'Gen'
31
31
  assert_book_num 1, 'Ge'
32
- assert_book_num 1, 'G'
33
32
  assert_book_num 55, '2 Tim'
34
33
  assert_book_num 55, '2Tim'
35
34
  assert_book_num 55, '2Tm'
@@ -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.fullref(ast)
82
- assert_equal @english, @english_formatter.fullref(ast)
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.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-03-03 00:00:00.000000000 Z
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.4'
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.4'
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: []