acts_as_scriptural 0.0.1

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: 64fb01e0e571241d7b4bc21eee9ad4a6f6261fce
4
+ data.tar.gz: 4a7f618751b72b9f268bfd654f2b742e4884459d
5
+ SHA512:
6
+ metadata.gz: 39846e58da1374cd9bdd9b87521e17f7f23e0eafa721d14c5efc67ae13ec3a18f9f70374b5a77b5beef5fdb531b7d91988423cae2fcd001bc6f2f325c193b0be
7
+ data.tar.gz: fbadacdc09ddd72751ac6bca1e9f35acdf9ef43b1aa6ced9b4821159809a7ca2cb0237e9ec1aaa92d92b6ba5c1e81ec8ab1aac2bcfd34f48b190b914c10adecc
@@ -0,0 +1,66 @@
1
+ Genesis,1,50
2
+ Exodus,2,40
3
+ Leviticus,3,27
4
+ Numbers,4,36
5
+ Deuteronomy,5,34
6
+ Joshua,6,24
7
+ Judges,7,21
8
+ Ruth,8,4
9
+ 1 Samuel,9,31
10
+ 2 Samuel,10,24
11
+ 1 Kings,11,22
12
+ 2 Kings,12,25
13
+ 1 Chronicles,13,29
14
+ 2 Chronicles,14,36
15
+ Ezra,15,10
16
+ Nehemiah,16,13
17
+ Esther,17,10
18
+ Job,18,42
19
+ Psalms,19,150
20
+ Proverbs,20,31
21
+ Ecclesiastes,21,12
22
+ SongofSongs,22,8
23
+ Isaiah,23,66
24
+ Jeremiah,24,52
25
+ Lamentations,25,5
26
+ Ezekiel,26,48
27
+ Daniel,27,12
28
+ Hosea,28,14
29
+ Joel,29,3
30
+ Amos,30,9
31
+ Obadiah,31,1
32
+ Jonah,32,4
33
+ Micah,33,7
34
+ Nahum,34,3
35
+ Habakkuk,35,3
36
+ Zephaniah,36,3
37
+ Haggai,37,2
38
+ Zechariah,38,14
39
+ Malachi,39,4
40
+ Matthew,40,28
41
+ Mark,41,16
42
+ Luke,42,24
43
+ John,43,21
44
+ Acts,44,28
45
+ Romans,45,16
46
+ 1 Corinthians,46,16
47
+ 2 Corinthians,47,13
48
+ Galatians,48,6
49
+ Ephesians,49,6
50
+ Philippians,50,4
51
+ Colossians,51,4
52
+ 1 Thessalonians,52,5
53
+ 2 Thessalonians,53,3
54
+ 1 Timothy,54,6
55
+ 2 Timothy,55,4
56
+ Titus,56,3
57
+ Philemon,57,1
58
+ Hebrews,58,13
59
+ James,59,5
60
+ 1 Peter,60,5
61
+ 2 Peter,61,3
62
+ 1 John,62,5
63
+ 2 John,63,1
64
+ 3 John,64,1
65
+ Jude,65,1
66
+ Revelation,66,22
@@ -0,0 +1,27 @@
1
+ require_relative 'bible'
2
+ require 'abbrev'
3
+
4
+
5
+ class ActsAsScriptural::AbbreviationLookup
6
+
7
+ def initialize
8
+ @hash = bible.book_names.abbrev.map{|k,v| [k.gsub(' ','').downcase,v]}.to_h
9
+ end
10
+
11
+ def fullname(str)
12
+ @hash[str.gsub(' ','').downcase]
13
+ end
14
+
15
+ def index_number(str)
16
+ bible.namehash[fullname(str)].index
17
+ end
18
+
19
+ def bible
20
+ @bible || ActsAsScriptural::Bible.new
21
+ end
22
+
23
+ def abbreviation_to_book(str)
24
+ bible.namehash[fullname(str)]
25
+ end
26
+
27
+ end
@@ -0,0 +1,34 @@
1
+ require_relative 'book'
2
+
3
+ class ActsAsScriptural::Bible
4
+
5
+ attr_accessor :namehash, :indexhash
6
+
7
+ def initialize
8
+ # two lookup tables...not too DRY
9
+ @namehash = Hash.new
10
+ @indexhash = Hash.new
11
+ import_from_file
12
+ end
13
+
14
+ def book_names
15
+ @namehash.map{|k,v| v.name}
16
+ end
17
+
18
+ def chapter_exists?(book_index, chapter_number)
19
+ @indexhash[book_index] &&
20
+ chapter_number.between?(1, @indexhash[book_index].num_chapters)
21
+ end
22
+
23
+ private
24
+
25
+ def import_from_file
26
+ datadir = Gem.datadir('acts_as_scriptural')
27
+ File.readlines("#{datadir}/english.txt").each do |line|
28
+ book_name, book_index, num_chapters = line.chomp.split(',')
29
+ book = ActsAsScriptural::Book.new(book_name, book_index.to_i, num_chapters.to_i)
30
+ @namehash[book_name] = book
31
+ @indexhash[book_index.to_i] = book
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ class ActsAsScriptural::Book
2
+
3
+ def initialize(name, index, num_chapters)
4
+ @name = name
5
+ @index = index
6
+ @num_chapters = num_chapters
7
+ end
8
+
9
+ attr_accessor :name, :index, :num_chapters
10
+
11
+ end
@@ -0,0 +1,17 @@
1
+ class ActsAsScriptural::Parser
2
+
3
+ def self.book_and_chapters_from_reference(reference)
4
+ regex = /^\s*([0-9]?\s*[a-zA-Z]+)\.?\s*([0-9]+)(?:\s*(?:-|..)[^0-9]*([0-9]+))?/
5
+ match = reference.match(regex)
6
+ if match
7
+ if match[3]
8
+ chapters = (match[2]..match[3]).to_a
9
+ else
10
+ chapters = [ match[2] ]
11
+ end
12
+ [ match[1], chapters.map(&:to_i) ]
13
+ else
14
+ [nil, nil]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ class ActsAsScriptural
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,47 @@
1
+ require_relative "acts_as_scriptural/version"
2
+ require_relative "acts_as_scriptural/book"
3
+ require_relative "acts_as_scriptural/bible"
4
+ require_relative "acts_as_scriptural/parser"
5
+ require_relative "acts_as_scriptural/abbreviation_lookup"
6
+
7
+
8
+
9
+
10
+ class ActsAsScriptural
11
+
12
+ attr_accessor :chapters
13
+
14
+ def initialize
15
+ @chapters = Array.new
16
+ end
17
+
18
+ def parse(str)
19
+ references = str.split(',')
20
+ references.each {|ref| parse_a_reference(ref) }
21
+ self
22
+ end
23
+
24
+ def parse_a_reference(reference)
25
+ book, chapters = Parser.book_and_chapters_from_reference(reference)
26
+ add_chapters(book, chapters)
27
+ end
28
+
29
+ def add_chapters(book, chapters)
30
+ book_index = lookup.index_number(book)
31
+ if book_index && chapters
32
+ chapters.each do |c|
33
+ @chapters << [book_index, c] if bible.chapter_exists?(book_index, c)
34
+ end
35
+ end
36
+ end
37
+
38
+ def bible
39
+ @bible || Bible.new
40
+ end
41
+
42
+ def lookup
43
+ @lookup || AbbreviationLookup.new
44
+ end
45
+
46
+
47
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_scriptural
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Philip Bradley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ description: 'Parse multibook, multiverse bible references of the form: Acts 1:1-10;
56
+ Eph 1:5-10; John 12:4'
57
+ email:
58
+ - pdbradley@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - data/acts_as_scriptural/english.txt
64
+ - lib/acts_as_scriptural.rb
65
+ - lib/acts_as_scriptural/abbreviation_lookup.rb
66
+ - lib/acts_as_scriptural/bible.rb
67
+ - lib/acts_as_scriptural/book.rb
68
+ - lib/acts_as_scriptural/parser.rb
69
+ - lib/acts_as_scriptural/version.rb
70
+ homepage: ''
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Parse multibook, multiverse bible references
94
+ test_files: []