pericope 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/pericope.rb +19 -15
  2. data/lib/pericope/version.rb +1 -1
  3. metadata +50 -54
data/lib/pericope.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'yaml'
2
4
  require 'pericope/version'
3
5
 
@@ -10,11 +12,18 @@ class Pericope
10
12
  :ranges
11
13
 
12
14
 
13
-
14
15
  def self.book_names
15
16
  @@book_names ||= ["Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", "Joshua", "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings", "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", "Job", "Psalm", "Proverbs", "Ecclesiastes", "Song of Songs", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah", "Malachi", "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 Corinthians", "2 Corinthians", "Galatians", "Ephesians", "Philippians", "Colossians", "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", "Titus", "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John ", "2 John", "3 John", "Jude", "Revelation"]
16
17
  end
17
18
 
19
+ def self.book_name_regexes
20
+ @@book_name_regexes ||= begin
21
+ book_abbreviations.map do |book|
22
+ [book, Regexp.new("\\b#{book[1]}\\b.? (#{ValidReference})", true)]
23
+ end
24
+ end
25
+ end
26
+
18
27
 
19
28
 
20
29
  def initialize(string_or_array)
@@ -240,9 +249,10 @@ private
240
249
  end
241
250
 
242
251
  def normalize_reference(reference)
243
- { %r{(\d+)[".](\d+)} => '\1:\2', # 12"5 and 12.5 -> 12:5
244
- %r{[^0-9,:;-]} => '' # remove everything but [0-9,;:-]
245
- }.each {|pattern, replacement| reference.gsub!(pattern, replacement)}
252
+ [ [%r{(\d+)[".](\d+)},'\1:\2'], # 12"5 and 12.5 -> 12:5
253
+ [%r{(–|—)},'-'], # convert em dash and en dash to -
254
+ [%r{[^0-9,:;\-–—]},''] # remove everything but [0-9,;:-]
255
+ ].each { |pattern, replacement| reference.gsub!(pattern, replacement) }
246
256
  reference
247
257
  end
248
258
 
@@ -345,15 +355,16 @@ private
345
355
  def self.match_all(text, &block)
346
356
  matches = []
347
357
  unmatched = text
348
- for book in book_abbreviations
349
- rx = Regexp.new("\\b#{book[1]}\\b.? (#{ValidReference})", true)
358
+
359
+ for book_regex in book_name_regexes
360
+ rx = book_regex[1]
350
361
  while (match = unmatched.match rx) # find all occurrences of pericopes in this book
351
362
  length = match.end(0) - match.begin(0)
352
363
 
353
364
  # after matching "2 Peter" don't match "Peter" again as "1 Peter"
354
365
  # but keep the same number of characters in the string so indices work
355
366
  unmatched = match.pre_match + ("*" * length) + match.post_match
356
- match.instance_variable_set('@book', book[0])
367
+ match.instance_variable_set('@book', book_regex[0][0])
357
368
  if block_given?
358
369
  yield match
359
370
  else
@@ -516,15 +527,8 @@ private
516
527
  22] # Revelation 66
517
528
  end
518
529
 
519
-
520
-
521
530
  ValidReference = begin
522
- chapter = '\d{1,3}' # matches 0-999
523
- verse = '\d{1,3}[ab]?' # matches 0-999 with or without 'a' or 'b' afterward
524
- chapter_verse = "#{chapter}(?:\\s?[.:\"]\\s?#{verse})?" # matches chapter with or without verse reference
525
- chapter_verse_range = "(?:#{chapter_verse}(?:\\s?[\\&\\-]\\s?(?:(?:#{chapter_verse})|(?:#{verse})))?)"
526
- # "(#{chapter}(?:[.:]#{verse})?(?:\\s?[\\&\\-]\\s?(?:#{verse}(?:[.:]\\d{1,3})?)?)" # chapter:verse reference
527
- reference = "#{chapter_verse_range}(?:\\s?[,;]\\s?#{chapter_verse_range})*" # multiple chapter:verse references
531
+ reference = '((\s*\d{1,3})(\s*[:\"\.]\s*\d{1,3}(a|b)?(\s*(,|;)\s*(\d{1,3}[:\"\.])?\s*\d{1,3}(a|b)?)*)?(\s*(-|–|—)\s*(\d{1,3}\s*[:\"\.])?(\d{1,3}(a|b)?)(\s*(,|;)\s*(\d{1,3}\s*[:\"\.])?\s*\d{1,3}(a|b)?)*)*)'
528
532
  end
529
533
 
530
534
 
@@ -1,3 +1,3 @@
1
1
  class Pericope
2
- VERSION = "0.5.2" unless defined?(::Pericope::Version)
2
+ VERSION = "0.5.3" unless defined?(::Pericope::Version)
3
3
  end
metadata CHANGED
@@ -1,47 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pericope
3
- version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 5
9
- - 2
10
- version: 0.5.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Bob Lail
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-10-26 00:00:00 -05:00
19
- default_executable: pericope
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: turn
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
35
46
  description:
36
- email:
47
+ email:
37
48
  - bob.lailfamily@gmail.com
38
- executables:
49
+ executables:
39
50
  - pericope
40
51
  extensions: []
41
-
42
52
  extra_rdoc_files: []
43
-
44
- files:
53
+ files:
45
54
  - bin/pericope
46
55
  - data/book_abbreviations.txt
47
56
  - data/chapter_verse_count.txt
@@ -53,41 +62,28 @@ files:
53
62
  - lib/pericope.rb
54
63
  - lib/tasks/pericope_tasks.rake
55
64
  - README.mdown
56
- has_rdoc: true
57
65
  homepage: http://github.com/boblail/Pericope
58
66
  licenses: []
59
-
60
67
  post_install_message:
61
68
  rdoc_options: []
62
-
63
- require_paths:
69
+ require_paths:
64
70
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
71
+ required_ruby_version: !ruby/object:Gem::Requirement
66
72
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
78
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 23
80
- segments:
81
- - 1
82
- - 3
83
- - 6
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
84
82
  version: 1.3.6
85
83
  requirements: []
86
-
87
84
  rubyforge_project:
88
- rubygems_version: 1.3.7
85
+ rubygems_version: 1.8.23
89
86
  signing_key:
90
87
  specification_version: 3
91
88
  summary: Parses Bible references
92
89
  test_files: []
93
-