bible_parser 1.0.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 +7 -0
- data/README.md +31 -0
- data/lib/bible_parser.rb +68 -0
- data/lib/bible_parser/book.rb +42 -0
- data/lib/bible_parser/chapter.rb +55 -0
- data/lib/bible_parser/errors.rb +6 -0
- data/lib/bible_parser/parsers.rb +10 -0
- data/lib/bible_parser/parsers/base.rb +9 -0
- data/lib/bible_parser/parsers/base/document.rb +56 -0
- data/lib/bible_parser/parsers/base/parser.rb +68 -0
- data/lib/bible_parser/parsers/osis.rb +2 -0
- data/lib/bible_parser/parsers/osis/book_ids.rb +94 -0
- data/lib/bible_parser/parsers/osis/document.rb +81 -0
- data/lib/bible_parser/parsers/osis/parser.rb +13 -0
- data/lib/bible_parser/parsers/usfx.rb +2 -0
- data/lib/bible_parser/parsers/usfx/document.rb +90 -0
- data/lib/bible_parser/parsers/usfx/parser.rb +13 -0
- data/lib/bible_parser/verse.rb +54 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 81b20722da2fe055932ce55362c9b9856b1b8263
|
4
|
+
data.tar.gz: 9c7c29b4fd023897ddc4d0263113bedef3cabe19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0e8c2264b7ea234ea116c46e0090b67915e28b9a596ae80517cc6725b2bd06c0d24e1411768449f8b2ece2bc97e373cb2ecd6fde7b49ddf1b717a3a212323aa
|
7
|
+
data.tar.gz: eaa58f82526d4a717c77ec58e8b2ce0f3c4b4d200d402839a899dfda0bdf769c2201205f960dc66c411391c861eb871ebb73903fae976a16bc6b9e8b54464efb
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# BibleParser
|
2
|
+
|
3
|
+
[](https://travis-ci.org/seven1m/bible_parser)
|
4
|
+
|
5
|
+
This is a Ruby library for parsing different bible XML formats.
|
6
|
+
|
7
|
+
For now, it only supports USFX and OSIS, but I hope to add support for other formats also.
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install bible_parser
|
13
|
+
```
|
14
|
+
|
15
|
+
## Use
|
16
|
+
|
17
|
+
You can get the a bible in XML format [here](https://github.com/seven1m/open-bibles).
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'bible_parser'
|
21
|
+
|
22
|
+
bible = BibleParser.new(File.open('web.usfx.xml'))
|
23
|
+
verse = bible.books.first.chapters.first.verses.first
|
24
|
+
# => <Genesis 1:1>
|
25
|
+
verse.text
|
26
|
+
# => "In the beginning, God created the heavens and the earth.\n"
|
27
|
+
```
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
Copyright (c) 2015 Tim Morgan. Licensed MIT. See LICENSE file.
|
data/lib/bible_parser.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative 'bible_parser/parsers'
|
2
|
+
require_relative 'bible_parser/errors'
|
3
|
+
require_relative 'bible_parser/book'
|
4
|
+
require_relative 'bible_parser/chapter'
|
5
|
+
require_relative 'bible_parser/verse'
|
6
|
+
|
7
|
+
require 'stringio'
|
8
|
+
|
9
|
+
class BibleParser
|
10
|
+
attr_reader :format
|
11
|
+
|
12
|
+
def initialize(io, format: nil)
|
13
|
+
if io.is_a?(String)
|
14
|
+
@io = StringIO.new(io)
|
15
|
+
elsif io.respond_to?(:read)
|
16
|
+
@io = io
|
17
|
+
else
|
18
|
+
fail(
|
19
|
+
Errors::UnknownIoObjectError,
|
20
|
+
"#{io.inspect} is neither a File nor a String object. Please pass a File or a String."
|
21
|
+
)
|
22
|
+
end
|
23
|
+
@format = format || detect_format
|
24
|
+
end
|
25
|
+
|
26
|
+
def each_book(&block)
|
27
|
+
@io.rewind
|
28
|
+
if block
|
29
|
+
parser.each_book(&block)
|
30
|
+
else
|
31
|
+
parser.enum_for(:each_book)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def books
|
36
|
+
each_book.to_a
|
37
|
+
end
|
38
|
+
|
39
|
+
def each_verse(&block)
|
40
|
+
@io.rewind
|
41
|
+
if block
|
42
|
+
parser.each_verse(&block)
|
43
|
+
else
|
44
|
+
parser.enum_for(:each_verse)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def verses
|
49
|
+
each_verse.to_a
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def parser
|
55
|
+
parser_class.new(@io)
|
56
|
+
end
|
57
|
+
|
58
|
+
def parser_class
|
59
|
+
PARSERS[format] or fail(Errors::ParserUnavailableError, "Parser for #{format.inspect} could not be loaded.")
|
60
|
+
end
|
61
|
+
|
62
|
+
def detect_format
|
63
|
+
PARSERS.each do |name, parser|
|
64
|
+
@io.rewind
|
65
|
+
return name if parser.new(@io).valid?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class BibleParser
|
2
|
+
class Book
|
3
|
+
attr_reader :num, :id, :title
|
4
|
+
|
5
|
+
def initialize(num:, id:, title:, parser:)
|
6
|
+
@num = num
|
7
|
+
@id = id
|
8
|
+
@title = title
|
9
|
+
@parser = parser
|
10
|
+
end
|
11
|
+
|
12
|
+
def each_chapter(&block)
|
13
|
+
if block
|
14
|
+
@parser.each_chapter(book_id: id, &block)
|
15
|
+
else
|
16
|
+
enum_for(:each_chapter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def chapters
|
21
|
+
each_chapter.to_a
|
22
|
+
end
|
23
|
+
|
24
|
+
def ==(other)
|
25
|
+
id == other.id
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"<#{to_s}>"
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :to_s, :title
|
33
|
+
|
34
|
+
def to_h
|
35
|
+
{
|
36
|
+
num: num,
|
37
|
+
id: id,
|
38
|
+
title: title
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class BibleParser
|
2
|
+
class Chapter
|
3
|
+
attr_reader :num, :book_id, :book_num, :book_title
|
4
|
+
|
5
|
+
def initialize(num:, book_id:, book_num:, book_title:, parser:)
|
6
|
+
@num = num
|
7
|
+
@book_id = book_id
|
8
|
+
@book_num = book_num
|
9
|
+
@book_title = book_title
|
10
|
+
@parser = parser
|
11
|
+
end
|
12
|
+
|
13
|
+
def each_verse(&block)
|
14
|
+
if block
|
15
|
+
@parser.each_verse(book_id: book_id, chapter_num: num, &block)
|
16
|
+
else
|
17
|
+
enum_for(:each_verse)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def verses
|
22
|
+
each_verse.to_a
|
23
|
+
end
|
24
|
+
|
25
|
+
def book
|
26
|
+
Book.new(
|
27
|
+
id: book_id,
|
28
|
+
num: book_num,
|
29
|
+
title: book_title,
|
30
|
+
parser: @parser
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def ==(other)
|
35
|
+
book_id == other.book_id && num == other.num
|
36
|
+
end
|
37
|
+
|
38
|
+
def inspect
|
39
|
+
"<#{to_s}>"
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
"#{book_title} #{num}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_h
|
47
|
+
{
|
48
|
+
num: num,
|
49
|
+
book_id: book_id,
|
50
|
+
book_num: book_num,
|
51
|
+
book_title: book_title
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
class BibleParser
|
4
|
+
module Parsers
|
5
|
+
module Base
|
6
|
+
class Document < Nokogiri::XML::SAX::Document
|
7
|
+
def initialize(io:, iterator: :verse, iterate_book_id: nil, iterate_chapter_num: nil, &block)
|
8
|
+
super()
|
9
|
+
@book_num = 0
|
10
|
+
@io = io
|
11
|
+
@iterator = iterator
|
12
|
+
@iterate_book_id = iterate_book_id
|
13
|
+
@iterate_chapter_num = iterate_chapter_num
|
14
|
+
@block = block
|
15
|
+
end
|
16
|
+
|
17
|
+
def end_book
|
18
|
+
return unless @book_title
|
19
|
+
return unless @iterator == :book
|
20
|
+
@block.call(
|
21
|
+
num: @book_num,
|
22
|
+
id: @book_id,
|
23
|
+
title: @book_title
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def end_chapter
|
28
|
+
return unless @chapter
|
29
|
+
return unless @iterator == :chapter
|
30
|
+
return if @iterate_book_id && @iterate_book_id != @book_id
|
31
|
+
@block.call(
|
32
|
+
num: @chapter,
|
33
|
+
book_id: @book_id,
|
34
|
+
book_num: @book_num,
|
35
|
+
book_title: @book_title
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def end_verse
|
40
|
+
@mode = nil
|
41
|
+
return unless @iterator == :verse
|
42
|
+
return if @iterate_book_id && @iterate_book_id != @book_id
|
43
|
+
return if @iterate_chapter_num && @iterate_chapter_num != @chapter
|
44
|
+
@block.call(
|
45
|
+
num: @verse,
|
46
|
+
book_id: @book_id,
|
47
|
+
book_num: @book_num,
|
48
|
+
book_title: @book_title,
|
49
|
+
chapter_num: @chapter,
|
50
|
+
text: @text
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
class BibleParser
|
4
|
+
module Parsers
|
5
|
+
module Base
|
6
|
+
class Parser
|
7
|
+
def initialize(io)
|
8
|
+
@io = io
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
fail NotImplementedError, "override #valid? in your Parser class"
|
13
|
+
end
|
14
|
+
|
15
|
+
def document_class
|
16
|
+
module_name = self.class.name.sub(/::Parser$/, '')
|
17
|
+
Kernel.const_get("#{module_name}::Document")
|
18
|
+
end
|
19
|
+
|
20
|
+
def each_book
|
21
|
+
@io.rewind
|
22
|
+
document = document_class.new(io: @io, iterator: :book) do |book|
|
23
|
+
yield Book.new(
|
24
|
+
num: book[:num],
|
25
|
+
id: book[:id],
|
26
|
+
title: book[:title],
|
27
|
+
parser: self
|
28
|
+
)
|
29
|
+
end
|
30
|
+
sax_parser = Nokogiri::XML::SAX::Parser.new(document)
|
31
|
+
sax_parser.parse(@io)
|
32
|
+
end
|
33
|
+
|
34
|
+
def each_chapter(book_id: nil, &block)
|
35
|
+
@io.rewind
|
36
|
+
document = document_class.new(io: @io, iterator: :chapter, iterate_book_id: book_id) do |chapter|
|
37
|
+
yield Chapter.new(
|
38
|
+
num: chapter[:num],
|
39
|
+
book_id: chapter[:book_id],
|
40
|
+
book_num: chapter[:book_num],
|
41
|
+
book_title: chapter[:book_title],
|
42
|
+
parser: self
|
43
|
+
)
|
44
|
+
end
|
45
|
+
sax_parser = Nokogiri::XML::SAX::Parser.new(document)
|
46
|
+
sax_parser.parse(@io)
|
47
|
+
end
|
48
|
+
|
49
|
+
def each_verse(book_id: nil, chapter_num: nil, &block)
|
50
|
+
@io.rewind
|
51
|
+
document = document_class.new(io: @io, iterator: :verse, iterate_book_id: book_id, iterate_chapter_num: chapter_num) do |verse|
|
52
|
+
yield Verse.new(
|
53
|
+
num: verse[:num],
|
54
|
+
text: verse[:text],
|
55
|
+
book_id: verse[:book_id],
|
56
|
+
book_num: verse[:book_num],
|
57
|
+
book_title: verse[:book_title],
|
58
|
+
chapter_num: verse[:chapter_num],
|
59
|
+
parser: self
|
60
|
+
)
|
61
|
+
end
|
62
|
+
sax_parser = Nokogiri::XML::SAX::Parser.new(document)
|
63
|
+
sax_parser.parse(@io)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
class BibleParser
|
2
|
+
module Parsers
|
3
|
+
module OSIS
|
4
|
+
module BookIDs
|
5
|
+
BOOK_IDS = {
|
6
|
+
'Gen' => 'GEN',
|
7
|
+
'Exod' => 'EXO',
|
8
|
+
'Lev' => 'LEV',
|
9
|
+
'Num' => 'NUM',
|
10
|
+
'Deut' => 'DEU',
|
11
|
+
'Josh' => 'JOS',
|
12
|
+
'Judg' => 'JDG',
|
13
|
+
'Ruth' => 'RUT',
|
14
|
+
'1Sam' => '1SA',
|
15
|
+
'2Sam' => '2SA',
|
16
|
+
'1Kgs' => '1KI',
|
17
|
+
'2Kgs' => '2KI',
|
18
|
+
'1Chr' => '1CH',
|
19
|
+
'2Chr' => '2CH',
|
20
|
+
'Ezra' => 'EZR',
|
21
|
+
'Neh' => 'NEH',
|
22
|
+
'Esth' => 'EST',
|
23
|
+
'Job' => 'JOB',
|
24
|
+
'Ps' => 'PSA',
|
25
|
+
'Prov' => 'PRO',
|
26
|
+
'Eccl' => 'ECC',
|
27
|
+
'Song' => 'SNG',
|
28
|
+
'Isa' => 'ISA',
|
29
|
+
'Jer' => 'JER',
|
30
|
+
'Lam' => 'LAM',
|
31
|
+
'Ezek' => 'EZK',
|
32
|
+
'Dan' => 'DAN',
|
33
|
+
'Hos' => 'HOS',
|
34
|
+
'Joel' => 'JOL',
|
35
|
+
'Amos' => 'AMO',
|
36
|
+
'Obad' => 'OBA',
|
37
|
+
'Jonah' => 'JON',
|
38
|
+
'Mic' => 'MIC',
|
39
|
+
'Nah' => 'NAM',
|
40
|
+
'Hab' => 'HAB',
|
41
|
+
'Zeph' => 'ZEP',
|
42
|
+
'Hag' => 'HAG',
|
43
|
+
'Zech' => 'ZEC',
|
44
|
+
'Mal' => 'MAL',
|
45
|
+
'Tob' => 'TOB',
|
46
|
+
'Jdt' => 'JDT',
|
47
|
+
'EsthGr' => 'ESG',
|
48
|
+
'Wis' => 'WIS',
|
49
|
+
'Sir' => 'SIR',
|
50
|
+
'Bar' => 'BAR',
|
51
|
+
'EpJer' => 'LJE',
|
52
|
+
'PrAzar' => 'S3Y',
|
53
|
+
'Sus' => 'SUS',
|
54
|
+
'Bel' => 'BEL',
|
55
|
+
'1Macc' => '1MA',
|
56
|
+
'2Macc' => '2MA',
|
57
|
+
'3Macc' => '3MA',
|
58
|
+
'4Macc' => '4MA',
|
59
|
+
'1Esd' => '1ES',
|
60
|
+
'2Esd' => '2ES',
|
61
|
+
'PrMan' => 'MAN',
|
62
|
+
'2Esd' => 'PS2',
|
63
|
+
'Matt' => 'MAT',
|
64
|
+
'Mark' => 'MRK',
|
65
|
+
'Luke' => 'LUK',
|
66
|
+
'John' => 'JHN',
|
67
|
+
'Acts' => 'ACT',
|
68
|
+
'Rom' => 'ROM',
|
69
|
+
'1Cor' => '1CO',
|
70
|
+
'2Cor' => '2CO',
|
71
|
+
'Gal' => 'GAL',
|
72
|
+
'Eph' => 'EPH',
|
73
|
+
'Phil' => 'PHP',
|
74
|
+
'Col' => 'COL',
|
75
|
+
'1Thess' => '1TH',
|
76
|
+
'2Thess' => '2TH',
|
77
|
+
'1Tim' => '1TI',
|
78
|
+
'2Tim' => '2TI',
|
79
|
+
'Titus' => 'TIT',
|
80
|
+
'Phlm' => 'PHM',
|
81
|
+
'Heb' => 'HEB',
|
82
|
+
'Jas' => 'JAS',
|
83
|
+
'1Pet' => '1PE',
|
84
|
+
'2Pet' => '2PE',
|
85
|
+
'1John' => '1JN',
|
86
|
+
'2John' => '2JN',
|
87
|
+
'3John' => '3JN',
|
88
|
+
'Jude' => 'JUD',
|
89
|
+
'Rev' => 'REV'
|
90
|
+
}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require_relative 'book_ids'
|
2
|
+
|
3
|
+
class BibleParser
|
4
|
+
module Parsers
|
5
|
+
module OSIS
|
6
|
+
class Document < Base::Document
|
7
|
+
include BookIDs
|
8
|
+
|
9
|
+
def start_element(name, attributes)
|
10
|
+
case name
|
11
|
+
when 'div'
|
12
|
+
end_verse if @mode == 'verse'
|
13
|
+
start_book(attributes)
|
14
|
+
when 'title'
|
15
|
+
set_book_title(attributes)
|
16
|
+
when 'chapter'
|
17
|
+
end_verse if @mode == 'verse'
|
18
|
+
start_chapter(attributes)
|
19
|
+
when 'verse'
|
20
|
+
end_verse if @mode == 'verse'
|
21
|
+
start_verse(attributes)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def end_element(name)
|
26
|
+
case name
|
27
|
+
when 'div'
|
28
|
+
if @book_id
|
29
|
+
end_book
|
30
|
+
@book_id = nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def start_book(attributes)
|
36
|
+
attributes = Hash[attributes]
|
37
|
+
return unless attributes['type'] == 'book'
|
38
|
+
id = attributes['osisID']
|
39
|
+
@book_num += 1
|
40
|
+
@book_id = BOOK_IDS[id] || id.upcase[0..2]
|
41
|
+
@mode = 'book'
|
42
|
+
@book_title = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_book_title(attributes)
|
46
|
+
attributes = Hash[attributes]
|
47
|
+
return unless attributes['type'] == 'main'
|
48
|
+
@book_title = attributes['short']
|
49
|
+
end
|
50
|
+
|
51
|
+
def end_book_title
|
52
|
+
@mode = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def start_chapter(attributes)
|
56
|
+
attributes = Hash[attributes]
|
57
|
+
if attributes['sID']
|
58
|
+
@chapter = attributes['n'].to_i
|
59
|
+
else
|
60
|
+
end_chapter
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def start_verse(attributes)
|
65
|
+
attributes = Hash[attributes]
|
66
|
+
return unless attributes['sID']
|
67
|
+
@verse = attributes['n'].to_i
|
68
|
+
@text = ''
|
69
|
+
@mode = 'verse'
|
70
|
+
end
|
71
|
+
|
72
|
+
def characters(string)
|
73
|
+
case @mode
|
74
|
+
when 'verse'
|
75
|
+
@text << string
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
class BibleParser
|
4
|
+
module Parsers
|
5
|
+
module USFX
|
6
|
+
class Document < Base::Document
|
7
|
+
# list of book ids that should be skipped
|
8
|
+
IGNORE_BOOK_IDS = %w(FRT)
|
9
|
+
|
10
|
+
def start_element(name, attributes)
|
11
|
+
case name
|
12
|
+
when 'book'
|
13
|
+
start_book(attributes)
|
14
|
+
when 'h'
|
15
|
+
start_book_title(attributes)
|
16
|
+
when 'c'
|
17
|
+
start_chapter(attributes)
|
18
|
+
when 'v'
|
19
|
+
end_verse if @mode == 'verse'
|
20
|
+
start_verse(attributes)
|
21
|
+
when 've'
|
22
|
+
end_verse
|
23
|
+
when 'f', 'x'
|
24
|
+
start_footnote(attributes)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def end_element(name)
|
29
|
+
case name
|
30
|
+
when 'book'
|
31
|
+
end_book
|
32
|
+
end_verse if @mode == 'verse'
|
33
|
+
when 'c'
|
34
|
+
end_chapter
|
35
|
+
end_verse if @mode == 'verse'
|
36
|
+
when 'h'
|
37
|
+
end_book_title
|
38
|
+
when 'f', 'x'
|
39
|
+
end_footnote
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def start_book(attributes)
|
44
|
+
id = Hash[attributes]['id']
|
45
|
+
return if IGNORE_BOOK_IDS.include?(id)
|
46
|
+
@book_num += 1
|
47
|
+
@book_id = id
|
48
|
+
@mode = 'book'
|
49
|
+
@book_title = ''
|
50
|
+
end
|
51
|
+
|
52
|
+
def start_book_title(_attributes)
|
53
|
+
@mode = 'book-title' if @mode == 'book'
|
54
|
+
end
|
55
|
+
|
56
|
+
def end_book_title
|
57
|
+
@book_title.strip! if @book_title
|
58
|
+
@mode = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def start_chapter(attributes)
|
62
|
+
@chapter = Hash[attributes]['id'].to_i
|
63
|
+
end
|
64
|
+
|
65
|
+
def start_verse(attributes)
|
66
|
+
@verse = Hash[attributes]['id'].to_i
|
67
|
+
@text = ''
|
68
|
+
@mode = 'verse'
|
69
|
+
end
|
70
|
+
|
71
|
+
def start_footnote(_attributes)
|
72
|
+
@mode = "footnote|#{@mode}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def end_footnote
|
76
|
+
@mode = @mode.split('|').last
|
77
|
+
end
|
78
|
+
|
79
|
+
def characters(string)
|
80
|
+
case @mode
|
81
|
+
when 'book-title'
|
82
|
+
@book_title << string.gsub(/\n/, '')
|
83
|
+
when 'verse'
|
84
|
+
@text << string
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class BibleParser
|
2
|
+
class Verse
|
3
|
+
attr_reader :num, :book_id, :book_num, :book_title, :chapter_num, :text
|
4
|
+
|
5
|
+
def initialize(num:, book_id:, book_num:, book_title:, chapter_num:, text:, parser:)
|
6
|
+
@num = num
|
7
|
+
@book_id = book_id
|
8
|
+
@book_num = book_num
|
9
|
+
@book_title = book_title
|
10
|
+
@chapter_num = chapter_num
|
11
|
+
@text = text
|
12
|
+
@parser = parser
|
13
|
+
end
|
14
|
+
|
15
|
+
def inspect
|
16
|
+
"<#{to_s}>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"#{book_title} #{chapter_num}:#{num}"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def book
|
25
|
+
Book.new(
|
26
|
+
id: book_id,
|
27
|
+
num: book_num,
|
28
|
+
title: book_title,
|
29
|
+
parser: @parser
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def chapter
|
34
|
+
Chapter.new(
|
35
|
+
book_id: book_id,
|
36
|
+
book_num: book_num,
|
37
|
+
book_title: book_title,
|
38
|
+
num: chapter_num,
|
39
|
+
parser: @parser
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_h
|
44
|
+
{
|
45
|
+
num: num,
|
46
|
+
book_id: book_id,
|
47
|
+
book_num: book_num,
|
48
|
+
book_title: book_title,
|
49
|
+
chapter_num: chapter_num,
|
50
|
+
text: text
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bible_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Morgan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email: tim@timmorgan.org
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- README.md
|
62
|
+
- lib/bible_parser.rb
|
63
|
+
- lib/bible_parser/book.rb
|
64
|
+
- lib/bible_parser/chapter.rb
|
65
|
+
- lib/bible_parser/errors.rb
|
66
|
+
- lib/bible_parser/parsers.rb
|
67
|
+
- lib/bible_parser/parsers/base.rb
|
68
|
+
- lib/bible_parser/parsers/base/document.rb
|
69
|
+
- lib/bible_parser/parsers/base/parser.rb
|
70
|
+
- lib/bible_parser/parsers/osis.rb
|
71
|
+
- lib/bible_parser/parsers/osis/book_ids.rb
|
72
|
+
- lib/bible_parser/parsers/osis/document.rb
|
73
|
+
- lib/bible_parser/parsers/osis/parser.rb
|
74
|
+
- lib/bible_parser/parsers/usfx.rb
|
75
|
+
- lib/bible_parser/parsers/usfx/document.rb
|
76
|
+
- lib/bible_parser/parsers/usfx/parser.rb
|
77
|
+
- lib/bible_parser/verse.rb
|
78
|
+
homepage: https://github.com/seven1m/bible_parser
|
79
|
+
licenses: []
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.3
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Library for parsing the bible in various formats
|
101
|
+
test_files: []
|