scripref 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3ca4f679be693441ac7736e45aa665afd11c9b51
4
+ data.tar.gz: 003e3c4548aa4157f7f337d62baefce20f12b7b1
5
+ SHA512:
6
+ metadata.gz: 509cbf4f5d0cd161ace9424f359c34cbe714aaceead2650ee6034a9af3ba67c9ddde0edc3aa30c950fcfd4a56aa9c50b4728a00f7a1ff638b1dc105f5025faf9
7
+ data.tar.gz: 5cebfb96816bc6c76fcf4872bdb8e436c8a3442a80a5da61b5969fc666159fbd5b4a620f6fae9b33c13da475e6cffbdb9b0b25d34533cf5cd8055bfa4945bb17
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ 0.3.0
2
+ Set unspecified chapter or verse values to nil instead to 1 or :max.
3
+ Example: parser.parse("Ruth 2") => [#<struct Scripref::Passage text="Ruth 2", b1=8, c1=2, v1=nil, b2=8, c2=2, v2=nil>]
4
+ Handle special case of books with only one chapter.
5
+ Allow addons for verses (e.g. Ruth 2:8a).
6
+ Parsing of book ranges is now possible.
7
+ Adding a formatter with minimal functionality.
8
+
1
9
  0.2.0
2
10
  Improve doc and refactoring ref_sep -> pass_sep.
3
11
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012 Jan Friedrich
1
+ Copyright (c) 2010-2015 Jan Friedrich
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ Scripref - A Library for parsing scripture references in real texts
2
+ ===================================================================
3
+
4
+ The goal is the possibility to parse even complex scripture references in any text.
5
+
6
+
7
+ License
8
+ -------
9
+
10
+ MIT style license, see file LICENSE.
data/Rakefile CHANGED
@@ -1,9 +1,5 @@
1
- require 'rim'
2
- require 'rim/check_version'
3
- require 'rim/gem'
4
- require 'rim/git'
5
- require 'rim/rimrc'
6
- require 'rim/test'
1
+ require 'rim/tire'
2
+ require 'rim/regtest'
7
3
 
8
4
  $:.unshift File.dirname(__FILE__) + '/lib'
9
5
  require 'scripref'
@@ -43,4 +43,40 @@ module ConstReader
43
43
  end
44
44
  end
45
45
 
46
+ # Define a getter and a setter method for one or more constant values.
47
+ # The value of the constant itself is not changed, instead
48
+ # a corresponding instance variable is used.
49
+ #
50
+ # Example:
51
+ # module M
52
+ # A = :ma
53
+ # extend ConstReader
54
+ # const_accessor :A
55
+ # end
56
+ # class C
57
+ # include M
58
+ # end
59
+ # c1 = C.new
60
+ # c1.a # => :ma
61
+ # c1.a = :ca
62
+ # c1.a # => :ca
63
+ # c2 = C.new
64
+ # c2.a # => :ma
65
+ def const_accessor *consts
66
+ consts.flatten.each do |c|
67
+ class_exec(c.to_s, c.to_s.downcase) do |c_name, m_name|
68
+ define_method m_name do
69
+ ivar = '@' << m_name
70
+ if instance_variable_defined? ivar
71
+ return instance_variable_get(ivar)
72
+ else
73
+ val = self.singleton_class.const_get c_name
74
+ instance_variable_set ivar, val
75
+ return val
76
+ end
77
+ end
78
+ attr_writer m_name
79
+ end
80
+ end
81
+ end
46
82
  end
@@ -29,12 +29,21 @@ module Scripref
29
29
  # Regular expression to match a book.
30
30
  BOOK_RE = Regexp.new(BOOKS_RES.map {|re| '(^' << re.to_s << ')' }.join('|'))
31
31
 
32
+ # Separator between chapter and verse.
33
+ CV_SEPARATOR = ':'
34
+
32
35
  # Regular expression to match a separator between chapter and verse.
33
36
  CV_SEP_RE = /:\s*/o
34
37
 
38
+ # Separator between a range.
39
+ HYPHEN_SEPARATOR = '-'
40
+
35
41
  # Regular expression to match a hyphen.
36
42
  HYPHEN_RE = /\s*-\s*/o
37
43
 
44
+ # Separator between passages.
45
+ PASS_SEPARATOR = '; '
46
+
38
47
  # Regular expression to match a separator between passages.
39
48
  PASS_SEP_RE = /;\s*/o
40
49
 
@@ -49,11 +58,6 @@ module Scripref
49
58
  # Regular expression to parse a reference
50
59
  REFERENCE_RE = /#{pass}(;\s*#{pass})*/o
51
60
 
52
- # Define instance methods for the mixin.
53
-
54
- extend ConstReader
55
- const_reader constants
56
-
57
61
  end
58
62
 
59
63
  end
@@ -0,0 +1,63 @@
1
+ # - encoding: utf-8 -
2
+
3
+ module Scripref
4
+
5
+ class Formatter
6
+
7
+ # @param mods one or more modules to include
8
+ def initialize *mods
9
+ @mods = mods
10
+ mods.each do |m|
11
+ m.class_eval do
12
+ extend ConstReader
13
+ const_accessor constants
14
+ end
15
+ extend m
16
+ end
17
+ end
18
+
19
+ # Formats a reference (array of passages) with full
20
+ # book names (i.e. Hebrews 3:8)
21
+ def fullref *reference
22
+ last_b = last_c = last_v = nil
23
+ pass_texts = reference.flatten.map do |pass|
24
+ s = ''
25
+ unless last_b == pass.b1
26
+ s << book_names[pass.b1 - 1]
27
+ last_b = pass.b1
28
+ end
29
+ unless last_c == pass.c1
30
+ s << ' ' << pass.c1.to_s
31
+ last_c = pass.c1
32
+ end
33
+ unless last_v == pass.v1
34
+ s << cv_separator << pass.v1.to_s
35
+ last_v = pass.v1
36
+ end
37
+ # second part
38
+ a2 = []
39
+ unless last_v == pass.v2
40
+ a2 << pass.v2.to_s
41
+ last_v = pass.v2
42
+ end
43
+ unless last_c == pass.c2
44
+ a2 << cv_separator
45
+ a2 << pass.c2.to_s
46
+ last_c = pass.c2
47
+ end
48
+ unless last_b == pass.b2
49
+ a2 << ' ' << book_names[pass.b2 - 1]
50
+ last_b = pass.b2
51
+ end
52
+ if ! a2.empty?
53
+ s << hyphen_separator
54
+ s << a2.reverse.join('')
55
+ end
56
+ s
57
+ end
58
+ pass_texts.join(pass_separator)
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -26,12 +26,21 @@ module Scripref
26
26
  # Regular expression to match a book.
27
27
  BOOK_RE = Regexp.new(BOOKS_RES.map {|re| '(^' << re.to_s << ')' }.join('|'))
28
28
 
29
+ # Separator between chapter and verse.
30
+ CV_SEPARATOR = ','
31
+
29
32
  # Regular expression to match a separator between chapter and verse.
30
33
  CV_SEP_RE = /,\s*/o
31
34
 
35
+ # Separator between a range.
36
+ HYPHEN_SEPARATOR = '-'
37
+
32
38
  # Regular expression to match a hyphen.
33
39
  HYPHEN_RE = /\s*-\s*/o
34
40
 
41
+ # Separator between passages.
42
+ PASS_SEPARATOR = '; '
43
+
35
44
  # Regular expression to match a separator between passages.
36
45
  PASS_SEP_RE = /;\s*/o
37
46
 
@@ -46,10 +55,25 @@ module Scripref
46
55
  # Regular expression to parse a reference
47
56
  REFERENCE_RE = /#{pass}(;\s*#{pass})*/o
48
57
 
49
- # Define instance methods for the mixin.
58
+ # try to parse first book
59
+ def b1
60
+ s = scan(book_re) or return nil
61
+ @text << s
62
+ @b1 = @b2 = book2num(s)
63
+
64
+ if book_has_only_one_chapter?(@b1)
65
+ @c1 = @c2 = 1
66
+ epsilon or (hyphen and b2) or v1 or nil
67
+ else
68
+ @c1 = @v1 = nil
69
+ @c2 = @v2 = nil
70
+ epsilon or (hyphen and b2) or c1 or nil
71
+ end
72
+ end
50
73
 
51
- extend ConstReader
52
- const_reader constants
74
+ def book_has_only_one_chapter? book
75
+ [31, 63, 64, 65].include?(book)
76
+ end
53
77
 
54
78
  end
55
79
 
@@ -7,10 +7,14 @@ module Scripref
7
7
 
8
8
  NUMBER_RE = /\d+\s*/
9
9
 
10
- # @param mods on ore more modules to include
10
+ # @param mods one or more modules to include
11
11
  def initialize *mods
12
12
  @mods = mods
13
13
  mods.each do |m|
14
+ m.class_eval do
15
+ extend ConstReader
16
+ const_reader constants
17
+ end
14
18
  extend m
15
19
  end
16
20
  end
@@ -34,10 +38,10 @@ module Scripref
34
38
  s = scan(book_re) or return nil
35
39
  @text << s
36
40
  @b1 = @b2 = book2num(s)
37
- @c1 = @v1 = 1
38
- @c2 = @v2 = :max
41
+ @c1 = @v1 = nil
42
+ @c2 = @v2 = nil
39
43
 
40
- epsilon or c1 or nil
44
+ epsilon or (hyphen and b2) or c1 or nil
41
45
  end
42
46
 
43
47
  # try parse first chapter
@@ -49,7 +53,7 @@ module Scripref
49
53
  if cv_sep
50
54
  v1 or nil
51
55
  elsif hyphen
52
- c2 or nil
56
+ b2 or c2 or nil
53
57
  elsif pass_sep
54
58
  b1 or c1
55
59
  else
@@ -67,15 +71,18 @@ module Scripref
67
71
  case addon
68
72
  when :f, :ff
69
73
  @v2 = addon
74
+ when :a, :b, :c
75
+ @a1 = addon
70
76
  end
71
77
  end
72
78
 
73
79
  if hyphen
80
+ b2 or (
74
81
  if check(Regexp.new(NUMBER_RE.source + cv_sep_re.source))
75
82
  c2
76
83
  else
77
84
  v2 or nil
78
- end
85
+ end)
79
86
  elsif pass_sep
80
87
  b1 or c1
81
88
  elsif verse_sep
@@ -85,6 +92,16 @@ module Scripref
85
92
  end
86
93
  end
87
94
 
95
+ # try to parse second book
96
+ def b2
97
+ s = scan(book_re) or return nil
98
+ @text << s
99
+ @b2 = book2num(s)
100
+ @c2 = @v2 = nil
101
+
102
+ epsilon or c2 or nil
103
+ end
104
+
88
105
  # try to parse second chapter
89
106
  def c2
90
107
  s = scan(NUMBER_RE) or return nil
@@ -104,6 +121,13 @@ module Scripref
104
121
  @text << s
105
122
  @v2 = s.to_i
106
123
 
124
+ if addon = verse_addon
125
+ case addon
126
+ when :a, :b, :c
127
+ @a2 = addon
128
+ end
129
+ end
130
+
107
131
  if verse_sep
108
132
  v1
109
133
  elsif pass_sep
@@ -175,8 +199,9 @@ module Scripref
175
199
  end
176
200
 
177
201
  def push_passage
178
- @result << Passage.new(@text, @b1, @c1, @v1, @b2, @c2, @v2)
202
+ @result << Passage.new(@text, @b1, @c1, @v1, @b2, @c2, @v2, a1: @a1, a2: @a2)
179
203
  @text = ''
204
+ @a1 = @a2 = nil
180
205
  end
181
206
 
182
207
  def book2num str
@@ -11,7 +11,7 @@ module Scripref
11
11
  attr_accessor :text
12
12
 
13
13
  # @param text text to parse
14
- # @param mods on ore more modules to include in processor and parser
14
+ # @param mods one or more modules to include in processor and parser
15
15
  def initialize text=nil, *mods
16
16
  @text = text
17
17
  @mods = mods
data/lib/scripref.rb CHANGED
@@ -1,16 +1,20 @@
1
1
  # - encoding: utf-8 -
2
2
  require 'scripref/parser'
3
3
  require 'scripref/processor'
4
+ require 'scripref/formatter'
4
5
  require 'scripref/english'
5
6
  require 'scripref/german'
6
7
 
7
8
  module Scripref
8
9
 
9
- VERSION = '0.2.0'
10
+ VERSION = '0.3.0'
10
11
 
11
- Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2)
12
+ Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2) do
13
+
14
+ def initialize text, b1, c1, v1, b2, c2, v2, opts={}
15
+ super text, b1, c1, v1, b2, c2, v2, opts[:a1], opts[:a2]
16
+ end
12
17
 
13
- class Passage
14
18
  alias to_s text
15
19
  end
16
20
 
data/regtest/parser.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'regtest'
2
+ require 'scripref'
3
+
4
+ include Regtest
5
+ include Scripref
6
+
7
+ $parser = Parser.new(German)
8
+
9
+ def s text
10
+ sample text do
11
+ res = $parser.parse(text)
12
+ res.map {|r| r.respond_to?(:to_h) ? r.to_h : r}
13
+ end
14
+ end
15
+
16
+ s 'Ruth 2,1a-11.15a; 3,7b.9-12b; Markus 4; 5,3a.18b-21a'
data/test/test_english.rb CHANGED
@@ -1,24 +1,26 @@
1
1
  # - encoding: utf-8 -
2
2
  require 'test/unit'
3
+ require 'test_helper'
3
4
  require 'scripref/english'
4
5
 
5
6
  class TestEnglish < Test::Unit::TestCase
6
7
 
8
+ include Test::Helper
7
9
  include Scripref::English
8
10
 
9
11
  def test_book_re
10
- assert_match 'Genesis', book_re
11
- assert_match 'Exodus', book_re
12
- assert_match 'Matthew', book_re
13
- assert_match '2 Timothy', book_re
14
- assert_not_match '2 2 Timothy', book_re
15
- assert_match 'Revelation', book_re
16
- assert_not_match 'something', book_re
17
- assert_match 'Gen', book_re
18
- assert_match 'Ex', book_re
19
- assert_match 'Mat', book_re
20
- assert_match '2 Tim', book_re
21
- assert_match 'Rev', book_re
12
+ assert_match book_re, 'Genesis'
13
+ assert_match book_re, 'Exodus'
14
+ assert_match book_re, 'Matthew'
15
+ assert_match book_re, '2 Timothy'
16
+ assert_not_match book_re, '2 2 Timothy'
17
+ assert_match book_re, 'Revelation'
18
+ assert_not_match book_re, 'something'
19
+ assert_match book_re, 'Gen'
20
+ assert_match book_re, 'Ex'
21
+ assert_match book_re, 'Mat'
22
+ assert_match book_re, '2 Tim'
23
+ assert_match book_re, 'Rev'
22
24
  end
23
25
 
24
26
  def test_book2num
@@ -40,4 +42,11 @@ class TestEnglish < Test::Unit::TestCase
40
42
  assert_equal num, @parser.parse(str).first.b1
41
43
  end
42
44
 
45
+ def test_book_with_only_one_chapter
46
+ @parser ||= Scripref::Parser.new(Scripref::English)
47
+ text = 'Obad 1:3'
48
+ ast = [pass(text, 31, 1, 3, 31, 1, 3)]
49
+ assert_parsed_ast_for_text ast, text
50
+ end
51
+
43
52
  end
@@ -0,0 +1,60 @@
1
+ # - encoding: utf-8 -
2
+ require 'test/unit'
3
+ require 'test_helper'
4
+ require 'scripref'
5
+ require 'scripref/english'
6
+ require 'scripref/formatter'
7
+ require 'scripref/german'
8
+ require 'scripref/parser'
9
+
10
+ class TestFormatter < Test::Unit::TestCase
11
+
12
+ include Test::Helper
13
+
14
+ def setup
15
+ @parser = Scripref::Parser.new(Scripref::German)
16
+ @german_formatter = Scripref::Formatter.new(Scripref::German)
17
+ @english_formatter = Scripref::Formatter.new(Scripref::English)
18
+ end
19
+
20
+ def test_one_verse
21
+ @german = 'Römer 6,23'
22
+ @english = 'Romans 6:23'
23
+ check_formatting
24
+ end
25
+
26
+ def test_simple_passage
27
+ @german = 'Römer 8,1-10'
28
+ @english = 'Romans 8:1-10'
29
+ check_formatting
30
+ end
31
+
32
+ def test_passage_with_chapter_change
33
+ @german = 'Römer 1,1-5,11'
34
+ @english = 'Romans 1:1-5:11'
35
+ check_formatting
36
+ end
37
+
38
+ def test_passage_with_book_change
39
+ @german = '1. Korinther 1,1-2. Korinther 13,13'
40
+ @english = '1 Corinthians 1:1-2 Corinthians 13:13'
41
+ check_formatting
42
+ end
43
+
44
+ def test_changed_hyphen_separator
45
+ @german = '1. Korinther 1,1 - 2. Korinther 13,13'
46
+ @english = '1 Corinthians 1:1 - 2 Corinthians 13:13'
47
+ @german_formatter.hyphen_separator = ' - '
48
+ @english_formatter.hyphen_separator = ' - '
49
+ check_formatting
50
+ end
51
+
52
+ private
53
+
54
+ def check_formatting
55
+ ast = @parser.parse(@german)
56
+ assert_equal @german, @german_formatter.fullref(ast)
57
+ assert_equal @english, @english_formatter.fullref(ast)
58
+ end
59
+
60
+ end
data/test/test_german.rb CHANGED
@@ -1,24 +1,26 @@
1
1
  # - encoding: utf-8 -
2
2
  require 'test/unit'
3
+ require 'test_helper'
3
4
  require 'scripref/german'
4
5
 
5
6
  class TestGerman < Test::Unit::TestCase
6
7
 
8
+ include Test::Helper
7
9
  include Scripref::German
8
10
 
9
11
  def test_book_re
10
- assert_match '1. Mose', book_re
11
- assert_match '2. Mose', book_re
12
- assert_match 'Matthäus', book_re
13
- assert_match '2. Timotheus', book_re
14
- assert_not_match '2. 2. Timotheus', book_re
15
- assert_match 'Offenbarung', book_re
16
- assert_not_match 'something', book_re
17
- assert_match '1. Mo', book_re
18
- assert_match '2.Mo', book_re
19
- assert_match 'Mat', book_re
20
- assert_match '2. Tim', book_re
21
- assert_match 'Off', book_re
12
+ assert_match book_re, '1. Mose'
13
+ assert_match book_re, '2. Mose'
14
+ assert_match book_re, 'Matthäus'
15
+ assert_match book_re, '2. Timotheus'
16
+ assert_not_match book_re, '2. 2. Timotheus'
17
+ assert_match book_re, 'Offenbarung'
18
+ assert_not_match book_re, 'something'
19
+ assert_match book_re, '1. Mo'
20
+ assert_match book_re, '2.Mo'
21
+ assert_match book_re, 'Mat'
22
+ assert_match book_re, '2. Tim'
23
+ assert_match book_re, 'Off'
22
24
  end
23
25
 
24
26
  def test_book2num
@@ -37,4 +39,11 @@ class TestGerman < Test::Unit::TestCase
37
39
  assert_equal num, @parser.parse(str).first.b1
38
40
  end
39
41
 
42
+ def test_book_with_only_one_chapter
43
+ @parser ||= Scripref::Parser.new(Scripref::German)
44
+ text = 'Obad 3'
45
+ ast = [pass(text, 31, 1, 3, 31, 1, 3)]
46
+ assert_parsed_ast_for_text ast, text
47
+ end
48
+
40
49
  end
@@ -0,0 +1,31 @@
1
+ module Test::Helper
2
+
3
+ def pass *args
4
+ Scripref::Passage.new(*args)
5
+ end
6
+
7
+ def assert_equal_passage expected, actual
8
+ assert_equal expected.text, actual.text, 'Parsed text'
9
+ assert_equal expected.b1, actual.b1, 'First book'
10
+ assert_equal expected.c1, actual.c1, 'First chapter'
11
+ assert_equal expected.v1, actual.v1, 'First verse'
12
+ assert_equal expected.b2, actual.b2, 'Second book'
13
+ assert_equal expected.c2, actual.c2, 'Second chapter'
14
+ assert_equal expected.v2, actual.v2, 'Second verse'
15
+ assert_equal expected.a1, actual.a1, 'First addon'
16
+ assert_equal expected.a2, actual.a2, 'Second addon'
17
+ end
18
+
19
+ def assert_parsed_ast_for_text expected_ast, text
20
+ res = @parser.parse(text)
21
+ assert_equal expected_ast.size, res.size, 'Array size of AST'
22
+ expected_ast.zip(res) do |expected_elem, actual_elem|
23
+ if !expected_elem.kind_of?(String)
24
+ assert_equal_passage expected_elem, actual_elem
25
+ else
26
+ assert_equal expected_elem, actual_elem
27
+ end
28
+ end
29
+ end
30
+
31
+ end
data/test/test_parser.rb CHANGED
@@ -1,21 +1,24 @@
1
1
  # - encoding: utf-8 -
2
2
  require 'test/unit'
3
+ require 'test_helper'
3
4
  require 'scripref'
4
5
 
5
6
  class TestParser < Test::Unit::TestCase
6
7
 
8
+ include Test::Helper
9
+
7
10
  def setup
8
11
  @parser = Scripref::Parser.new(Scripref::German)
9
12
  end
10
13
 
11
14
  def test_only_book
12
15
  text = 'Ruth'
13
- assert_parsed_ast_for_text [pass(text, 8, 1, 1, 8, :max, :max)], text
16
+ assert_parsed_ast_for_text [pass(text, 8, nil, nil, 8, nil, nil)], text
14
17
  end
15
18
 
16
19
  def test_book_and_chapter
17
20
  text = 'Ruth 2'
18
- assert_parsed_ast_for_text [pass(text, 8, 2, 1, 8, 2, :max)], text
21
+ assert_parsed_ast_for_text [pass(text, 8, 2, nil, 8, 2, nil)], text
19
22
  end
20
23
 
21
24
  def test_book_chapter_and_verse
@@ -35,7 +38,22 @@ class TestParser < Test::Unit::TestCase
35
38
 
36
39
  def test_chapter_range
37
40
  text = 'Ruth 2-3'
38
- assert_parsed_ast_for_text [pass(text, 8, 2, 1, 8, 3, :max)], text
41
+ assert_parsed_ast_for_text [pass(text, 8, 2, nil, 8, 3, nil)], text
42
+ end
43
+
44
+ def test_book_range
45
+ text = '1. Mose - Offenbarung'
46
+ assert_parsed_ast_for_text [pass(text, 1, nil, nil, 66, nil, nil)], text
47
+ end
48
+
49
+ def test_book_chapter_range
50
+ text = '1. Mose 1 - Offenbarung 22'
51
+ assert_parsed_ast_for_text [pass(text, 1, 1, nil, 66, 22, nil)], text
52
+ end
53
+
54
+ def test_book_chapter_verse_range
55
+ text = '1. Mose 1,1-Offenbarung 22,21'
56
+ assert_parsed_ast_for_text [pass(text, 1, 1, 1, 66, 22, 21)], text
39
57
  end
40
58
 
41
59
  def test_one_following_verse
@@ -48,6 +66,28 @@ class TestParser < Test::Unit::TestCase
48
66
  assert_parsed_ast_for_text [pass(text, 8, 2, 5, 8, 2, :ff)], text
49
67
  end
50
68
 
69
+ def test_first_addon
70
+ text = 'Ruth 2,5a'
71
+ assert_parsed_ast_for_text [pass(text, 8, 2, 5, 8, 2, 5, a1: :a)], text
72
+ end
73
+
74
+ def test_second_addon
75
+ text = 'Ruth 2,5-7a'
76
+ assert_parsed_ast_for_text [pass(text, 8, 2, 5, 8, 2, 7, a2: :a)], text
77
+ end
78
+
79
+ def test_both_addons
80
+ text = 'Ruth 2,5b-7a'
81
+ assert_parsed_ast_for_text [pass(text, 8, 2, 5, 8, 2, 7, a1: :b, a2: :a)], text
82
+ end
83
+
84
+ def test_reset_addons
85
+ @parser.parse 'Ruth 2,5b-7a'
86
+ text = 'Ruth'
87
+ assert_parsed_ast_for_text [pass(text, 8, nil, nil, 8, nil, nil)], text
88
+ end
89
+
90
+
51
91
  ######################################################################
52
92
  # more than one reference
53
93
  ######################################################################
@@ -67,13 +107,13 @@ class TestParser < Test::Unit::TestCase
67
107
  def test_two_chapters_same_book
68
108
  text = 'Ruth 2; 5'
69
109
  t1, t2 = text.split('; ')
70
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, :max), '; ', pass(t2, 8, 5, 1, 8, 5, :max)], text
110
+ assert_parsed_ast_for_text [pass(t1, 8, 2, nil, 8, 2, nil), '; ', pass(t2, 8, 5, nil, 8, 5, nil)], text
71
111
  end
72
112
 
73
113
  def test_two_chapters_different_book
74
114
  text = 'Ruth 2; Markus 4'
75
115
  t1, t2 = text.split('; ')
76
- assert_parsed_ast_for_text [pass(t1, 8, 2, 1, 8, 2, :max), '; ', pass(t2, 41, 4, 1, 41, 4, :max)], text
116
+ assert_parsed_ast_for_text [pass(t1, 8, 2, nil, 8, 2, nil), '; ', pass(t2, 41, 4, nil, 41, 4, nil)], text
77
117
  end
78
118
 
79
119
  def test_two_verses
@@ -128,39 +168,11 @@ class TestParser < Test::Unit::TestCase
128
168
  pass(t2, 8, 2, 15, 8, 2, 15), '; ',
129
169
  pass(t3, 8, 3, 7, 8, 3, 7), '.',
130
170
  pass(t4, 8, 3, 9, 8, 3, 12), '; ',
131
- pass(t5, 41, 4, 1, 41, 4, :max), '; ',
171
+ pass(t5, 41, 4, nil, 41, 4, nil), '; ',
132
172
  pass(t6, 41, 5, 3, 41, 5, 3), '.',
133
173
  pass(t7, 41, 5, 18, 41, 5, 21)
134
174
  ]
135
175
  assert_parsed_ast_for_text ast, text
136
176
  end
137
177
 
138
- protected
139
-
140
- def pass *args
141
- Scripref::Passage.new(*args)
142
- end
143
-
144
- def assert_equal_passage expected, actual
145
- assert_equal expected.text, actual.text, 'Parsed text'
146
- assert_equal expected.b1, actual.b1, 'First book'
147
- assert_equal expected.c1, actual.c1, 'First chapter'
148
- assert_equal expected.v1, actual.v1, 'First verse'
149
- assert_equal expected.b2, actual.b2, 'Second book'
150
- assert_equal expected.c2, actual.c2, 'Second chapter'
151
- assert_equal expected.v2, actual.v2, 'Second verse'
152
- end
153
-
154
- def assert_parsed_ast_for_text expected_ast, text
155
- res = @parser.parse(text)
156
- assert_equal expected_ast.size, res.size, 'Array size of AST'
157
- expected_ast.zip(res) do |expected_elem, actual_elem|
158
- if !expected_elem.kind_of?(String)
159
- assert_equal_passage expected_elem, actual_elem
160
- else
161
- assert_equal expected_elem, actual_elem
162
- end
163
- end
164
- end
165
-
166
178
  end
@@ -7,7 +7,7 @@ class TestProcessor < Test::Unit::TestCase
7
7
  def setup
8
8
  @text = 'Some text Mt 1,1 and Mr 2 and so on ...'
9
9
  @mt = [Scripref::Passage.new('Mt 1,1 ', 40, 1, 1, 40, 1, 1)]
10
- @mr = [Scripref::Passage.new('Mr 2 ', 41, 2, 1, 41, 2, :max)]
10
+ @mr = [Scripref::Passage.new('Mr 2 ', 41, 2, nil, 41, 2, nil)]
11
11
  @processor = Scripref::Processor.new(@text, Scripref::German)
12
12
  @chunks = ['Some text ', @mt, 'and ', @mr, 'and so on ...']
13
13
  end
metadata CHANGED
@@ -1,66 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: scripref
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Jan Friedrich
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2012-03-28 00:00:00 Z
14
- dependencies: []
15
-
16
- description: ""
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rim
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: regtest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ description: ''
17
42
  email:
18
43
  executables: []
19
-
20
44
  extensions: []
21
-
22
45
  extra_rdoc_files: []
23
-
24
- files:
46
+ files:
25
47
  - CHANGELOG
26
48
  - LICENSE
49
+ - README.md
27
50
  - Rakefile
51
+ - lib/scripref.rb
28
52
  - lib/scripref/const_reader.rb
29
53
  - lib/scripref/english.rb
54
+ - lib/scripref/formatter.rb
30
55
  - lib/scripref/german.rb
31
56
  - lib/scripref/parser.rb
32
57
  - lib/scripref/processor.rb
33
- - lib/scripref.rb
58
+ - regtest/parser.rb
34
59
  - test/test_english.rb
60
+ - test/test_formatter.rb
35
61
  - test/test_german.rb
62
+ - test/test_helper.rb
36
63
  - test/test_parser.rb
37
64
  - test/test_processor.rb
38
65
  homepage: http://gitorious.org/scripref
39
66
  licenses: []
40
-
67
+ metadata: {}
41
68
  post_install_message:
42
69
  rdoc_options: []
43
-
44
- require_paths:
70
+ require_paths:
45
71
  - lib
46
- required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
- requirements:
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
49
74
  - - ">="
50
- - !ruby/object:Gem::Version
51
- version: "0"
52
- required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
55
79
  - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
58
82
  requirements: []
59
-
60
83
  rubyforge_project:
61
- rubygems_version: 1.8.19
84
+ rubygems_version: 2.4.5
62
85
  signing_key:
63
- specification_version: 3
86
+ specification_version: 4
64
87
  summary: Library for parsing scripture references in real texts.
65
88
  test_files: []
66
-