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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 21205b3151c514f536d81a727778d0ec3ad46a48
4
- data.tar.gz: 6869a6575b30d177406baa6a9867a7f1534eb3e4
2
+ SHA256:
3
+ metadata.gz: aa9e6be87d748d3bd5a78a583cd7cffe7785548debe997f15478da1d19454b2d
4
+ data.tar.gz: c1cd0125bf8fdee4befaf21409746f1f71bbcc7931e67d91f4abfb68d67dd624
5
5
  SHA512:
6
- metadata.gz: cf00d9e8951725ad7551eafbaf9e841c8549a56d7c90a9aa7de82e158702403bcdc63816dab72f415e996bf0de8807a9e7b75c2c66b09d1690568bc0771b3871
7
- data.tar.gz: 53d7ed2ade506a9adaa0933537884657b86e2dc89aa596a922c9b51a65a908417a041312173c6583e0dc23027eb745678920ed0fa93dea55543d88ca75d8a4d6
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
@@ -15,5 +15,6 @@ Rim.setup do
15
15
  if feature_loaded? 'rim/irb'
16
16
  irb_requires %w(scripref scripref/include scripref/pipelining)
17
17
  end
18
+ ruby_version '>=2.5.0'
18
19
  test_warning false
19
20
  end
@@ -78,6 +78,9 @@ module Scripref
78
78
  [31, 57, 63, 64, 65].include?(book)
79
79
  end
80
80
 
81
+ # Regular expression to match punctuation marks
82
+ PUNCTUATION_MARKS_RE = /[:;.\-]\s*/
83
+
81
84
  # Generate attr_reader methods for all constants
82
85
  extend ConstReader
83
86
  const_reader constants
@@ -74,6 +74,9 @@ module Scripref
74
74
  [31, 57, 63, 64, 65].include?(book)
75
75
  end
76
76
 
77
+ # Regular expression to match punctuation marks
78
+ PUNCTUATION_MARKS_RE = /[,;.\-]\s*/
79
+
77
80
  # Generate attr_reader methods for all constants
78
81
  extend ConstReader
79
82
  const_reader constants
@@ -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
- if names.size != 1
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
@@ -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
@@ -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.scan_until(reference_re)
30
- yield @parser.parse(scanner.matched)
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
- yield scanner[1] unless scanner[1].empty?
45
- yield @parser.parse(scanner[2])
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 = '(' << [postfix_one_following_verse_re, postfix_more_following_verses_re, verse_addon_re].map {|e| verse_re.source << e.source}.join(')|(') << ')'
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
- '(', book_re, ')', '((', verse_with_optional_addon_or_postfix, ')|(', chapter_re, ')|(', verse_re, '))',
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
@@ -3,7 +3,7 @@ require 'delegate'
3
3
 
4
4
  module Scripref
5
5
 
6
- VERSION = '0.12.0'
6
+ VERSION = '0.13.0'
7
7
 
8
8
  autoload :Bookname, 'scripref/bookname'
9
9
  autoload :English, 'scripref/english'
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
- a = [c.b1, c.c1, c.v1, c.b2, c.c2, c.v2]
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
@@ -1,11 +1,10 @@
1
1
  require 'regtest'
2
2
  require 'scripref'
3
3
 
4
- include Regtest
5
4
  include Scripref
6
5
 
7
6
  def s text
8
- sample text do
7
+ Regtest.sample text do
9
8
  res = Parser.new(German).parse(text)
10
9
  res.map {|r| r.respond_to?(:to_h) ? r.to_h : r.to_s}
11
10
  end
data/regtest/processor.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'regtest'
2
2
  require 'scripref'
3
3
 
4
- include Regtest
5
4
  include Scripref
6
5
 
7
6
  def s text
8
- sample text do
7
+ Regtest.sample text do
9
8
  p = Processor.new(text, German)
10
9
  p.each.to_a
11
10
  end