scripref 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ca4f679be693441ac7736e45aa665afd11c9b51
4
- data.tar.gz: 003e3c4548aa4157f7f337d62baefce20f12b7b1
3
+ metadata.gz: d474cd23788d8e7fba5f76d10c0dae60e205000e
4
+ data.tar.gz: f2ca72e4fd6bb01e0d48d2b177e469cc1db5bad6
5
5
  SHA512:
6
- metadata.gz: 509cbf4f5d0cd161ace9424f359c34cbe714aaceead2650ee6034a9af3ba67c9ddde0edc3aa30c950fcfd4a56aa9c50b4728a00f7a1ff638b1dc105f5025faf9
7
- data.tar.gz: 5cebfb96816bc6c76fcf4872bdb8e436c8a3442a80a5da61b5969fc666159fbd5b4a620f6fae9b33c13da475e6cffbdb9b0b25d34533cf5cd8055bfa4945bb17
6
+ metadata.gz: 46913ffca73f184d92fbc33d2d02f311a8e456575cd229cd3d6cd05ee63a989c04d2102118afa00cf9562ce79bd6e84904b770a747952e3951fd1a672915c725
7
+ data.tar.gz: bcb8a59ae40f73e66fcc2676c6fe50fd2ddc02dd60fbd29291e6541516d0432a46b0af6e8aad2a43f59eca45ba567db5b8828b034998c0a114ba9f1d01b8c683
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.4.0
2
+ Handling books with only one chapter correct.
3
+
1
4
  0.3.0
2
5
  Set unspecified chapter or verse values to nil instead to 1 or :max.
3
6
  Example: parser.parse("Ruth 2") => [#<struct Scripref::Passage text="Ruth 2", b1=8, c1=2, v1=nil, b2=8, c2=2, v2=nil>]
@@ -21,37 +21,54 @@ module Scripref
21
21
  def fullref *reference
22
22
  last_b = last_c = last_v = nil
23
23
  pass_texts = reference.flatten.map do |pass|
24
+ changed = false
24
25
  s = ''
25
- unless last_b == pass.b1
26
+ if changed || last_b != pass.b1
26
27
  s << book_names[pass.b1 - 1]
27
28
  last_b = pass.b1
29
+ changed = true
28
30
  end
29
- unless last_c == pass.c1
30
- s << ' ' << pass.c1.to_s
31
+ if changed || last_c != pass.c1
32
+ s << ' '
33
+ if ! Scripref.book_has_only_one_chapter?(pass.b1)
34
+ s << pass.c1.to_s
35
+ end
31
36
  last_c = pass.c1
37
+ changed = true
32
38
  end
33
- unless last_v == pass.v1
34
- s << cv_separator << pass.v1.to_s
39
+ if changed || last_v != pass.v1
40
+ if ! Scripref.book_has_only_one_chapter?(pass.b1)
41
+ s << cv_separator
42
+ end
43
+ s << pass.v1.to_s
35
44
  last_v = pass.v1
45
+ changed = true
36
46
  end
37
47
  # second part
48
+ changed = false
38
49
  a2 = []
39
- unless last_v == pass.v2
40
- a2 << pass.v2.to_s
41
- last_v = pass.v2
50
+ if changed || last_b != pass.b2
51
+ a2 << book_names[pass.b2 - 1]
52
+ last_b = pass.b2
53
+ changed = true
42
54
  end
43
- unless last_c == pass.c2
44
- a2 << cv_separator
45
- a2 << pass.c2.to_s
55
+ if changed || last_c != pass.c2
56
+ a2 << ' ' if pass.b1 != pass.b2
57
+ if ! Scripref.book_has_only_one_chapter?(pass.b2)
58
+ a2 << pass.c2.to_s
59
+ a2 << cv_separator
60
+ end
46
61
  last_c = pass.c2
62
+ changed = true
47
63
  end
48
- unless last_b == pass.b2
49
- a2 << ' ' << book_names[pass.b2 - 1]
50
- last_b = pass.b2
64
+ if changed || last_v != pass.v2
65
+ a2 << pass.v2.to_s
66
+ last_v = pass.v2
67
+ changed = true
51
68
  end
52
69
  if ! a2.empty?
53
70
  s << hyphen_separator
54
- s << a2.reverse.join('')
71
+ s << a2.join('')
55
72
  end
56
73
  s
57
74
  end
@@ -55,26 +55,6 @@ module Scripref
55
55
  # Regular expression to parse a reference
56
56
  REFERENCE_RE = /#{pass}(;\s*#{pass})*/o
57
57
 
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
73
-
74
- def book_has_only_one_chapter? book
75
- [31, 63, 64, 65].include?(book)
76
- end
77
-
78
58
  end
79
59
 
80
60
  end
@@ -38,10 +38,21 @@ module Scripref
38
38
  s = scan(book_re) or return nil
39
39
  @text << s
40
40
  @b1 = @b2 = book2num(s)
41
- @c1 = @v1 = nil
42
- @c2 = @v2 = nil
43
41
 
44
- epsilon or (hyphen and b2) or c1 or nil
42
+ if check(Regexp.new(NUMBER_RE.source + cv_sep_re.source))
43
+ @c1 = @v1 = nil
44
+ @c2 = @v2 = nil
45
+ c1
46
+ else
47
+ if Scripref.book_has_only_one_chapter?(@b1)
48
+ @c1 = @c2 = 1
49
+ epsilon or (hyphen and b2) or v1 or nil
50
+ else
51
+ @c1 = @v1 = nil
52
+ @c2 = @v2 = nil
53
+ epsilon or (hyphen and b2) or c1 or nil
54
+ end
55
+ end
45
56
  end
46
57
 
47
58
  # try parse first chapter
@@ -99,7 +110,16 @@ module Scripref
99
110
  @b2 = book2num(s)
100
111
  @c2 = @v2 = nil
101
112
 
102
- epsilon or c2 or nil
113
+ if check(Regexp.new(NUMBER_RE.source + cv_sep_re.source))
114
+ c2
115
+ else
116
+ if Scripref.book_has_only_one_chapter?(@b2)
117
+ @c2 = 1
118
+ epsilon or v2 or nil
119
+ else
120
+ epsilon or c2 or nil
121
+ end
122
+ end
103
123
  end
104
124
 
105
125
  # try to parse second chapter
@@ -220,4 +240,9 @@ module Scripref
220
240
 
221
241
  end
222
242
 
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
+ end
247
+
223
248
  end
data/lib/scripref.rb CHANGED
@@ -7,7 +7,7 @@ require 'scripref/german'
7
7
 
8
8
  module Scripref
9
9
 
10
- VERSION = '0.3.0'
10
+ VERSION = '0.4.0'
11
11
 
12
12
  Passage = Struct.new(:text, :b1, :c1, :v1, :b2, :c2, :v2, :a1, :a2) do
13
13
 
data/test/test_english.rb CHANGED
@@ -42,11 +42,4 @@ class TestEnglish < Test::Unit::TestCase
42
42
  assert_equal num, @parser.parse(str).first.b1
43
43
  end
44
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
-
52
45
  end
@@ -41,6 +41,31 @@ class TestFormatter < Test::Unit::TestCase
41
41
  check_formatting
42
42
  end
43
43
 
44
+ def test_passage_with_different_chapter_and_same_verse
45
+ @german = '2. Petrus 1,13-2,13'
46
+ @english = '2 Peter 1:13-2:13'
47
+ check_formatting
48
+ end
49
+
50
+ def test_book_with_only_one_chapter
51
+ @german = 'Obadja 3'
52
+ @english = 'Obadiah 3'
53
+ check_formatting
54
+ end
55
+
56
+ def test_book_with_only_one_chapter_range
57
+ @german = 'Obadja 3-5'
58
+ @english = 'Obadiah 3-5'
59
+ check_formatting
60
+ end
61
+
62
+ def test_book_with_only_one_chapter_at_end_of_range
63
+ @german = 'Amos 2,4-Obadja 3'
64
+ @english = 'Amos 2:4-Obadiah 3'
65
+ check_formatting
66
+ end
67
+
68
+
44
69
  def test_changed_hyphen_separator
45
70
  @german = '1. Korinther 1,1 - 2. Korinther 13,13'
46
71
  @english = '1 Corinthians 1:1 - 2 Corinthians 13:13'
data/test/test_german.rb CHANGED
@@ -39,11 +39,4 @@ class TestGerman < Test::Unit::TestCase
39
39
  assert_equal num, @parser.parse(str).first.b1
40
40
  end
41
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
-
49
42
  end
data/test/test_parser.rb CHANGED
@@ -87,6 +87,38 @@ class TestParser < Test::Unit::TestCase
87
87
  assert_parsed_ast_for_text [pass(text, 8, nil, nil, 8, nil, nil)], text
88
88
  end
89
89
 
90
+ def test_book_with_only_one_chapter
91
+ text = 'Obad 3'
92
+ assert_parsed_ast_for_text [pass(text, 31, 1, 3, 31, 1, 3)], text
93
+ text = 'Obad 1,3'
94
+ assert_parsed_ast_for_text [pass(text, 31, 1, 3, 31, 1, 3)], text
95
+ text = 'Obad 1'
96
+ assert_parsed_ast_for_text [pass(text, 31, 1, 1, 31, 1, 1)], text
97
+ text = 'Obad 1,1'
98
+ assert_parsed_ast_for_text [pass(text, 31, 1, 1, 31, 1, 1)], text
99
+ end
100
+
101
+ def test_book_with_only_one_chapter_range
102
+ text = 'Obad 3-5'
103
+ assert_parsed_ast_for_text [pass(text, 31, 1, 3, 31, 1, 5)], text
104
+ text = 'Obad 1,3-5'
105
+ assert_parsed_ast_for_text [pass(text, 31, 1, 3, 31, 1, 5)], text
106
+ text = 'Obad 1-4'
107
+ assert_parsed_ast_for_text [pass(text, 31, 1, 1, 31, 1, 4)], text
108
+ text = 'Obad 1,1-4'
109
+ assert_parsed_ast_for_text [pass(text, 31, 1, 1, 31, 1, 4)], text
110
+ end
111
+
112
+ def test_book_with_only_one_chapter_at_end_of_range
113
+ text = 'Amos 2,4 - Obad 3'
114
+ assert_parsed_ast_for_text [pass(text, 30, 2, 4, 31, 1, 3)], text
115
+ text = 'Amos 2,4 - Obad 1,3'
116
+ assert_parsed_ast_for_text [pass(text, 30, 2, 4, 31, 1, 3)], text
117
+ text = 'Amos 2,4 - Obad 1'
118
+ assert_parsed_ast_for_text [pass(text, 30, 2, 4, 31, 1, 1)], text
119
+ text = 'Amos 2,4 - Obad 1,1'
120
+ assert_parsed_ast_for_text [pass(text, 30, 2, 4, 31, 1, 1)], text
121
+ end
90
122
 
91
123
  ######################################################################
92
124
  # more than one reference
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.3.0
4
+ version: 0.4.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-02 00:00:00.000000000 Z
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rim