scriptura 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +73 -0
- data/lib/scriptura/data.rb +1576 -0
- data/lib/scriptura/scripture.rb +25 -0
- data/lib/scriptura/scripture_book.rb +67 -0
- data/lib/scriptura/scripture_chapter.rb +43 -0
- data/lib/scriptura/scripture_reference.rb +56 -0
- data/lib/scriptura/scripture_verse.rb +37 -0
- data/lib/scriptura.rb +7 -0
- metadata +69 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
module ScriptureMeta
|
2
|
+
def self.old_testament_books
|
3
|
+
books = []
|
4
|
+
(1..39).each do |book_number|
|
5
|
+
books << ScriptureBook.new(book_number)
|
6
|
+
end
|
7
|
+
books
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.new_testament_books
|
11
|
+
books = []
|
12
|
+
(40..66).each do |book_number|
|
13
|
+
books << ScriptureBook.new(book_number)
|
14
|
+
end
|
15
|
+
books
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.books
|
19
|
+
old_testament_books + new_testament_books
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.book_names
|
23
|
+
books.map(&:name)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module ScriptureMeta
|
2
|
+
class ScriptureBook
|
3
|
+
def initialize(number)
|
4
|
+
raise ArgumentError, 'book number cannot be converted to an integer' unless number.respond_to?(:to_i)
|
5
|
+
raise 'book number should be within 1-66' unless (1..66).cover?(number.to_i)
|
6
|
+
@number = number.to_i
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.find_by_name name
|
10
|
+
hash = METADATA.find{|book| book['name'] == name}
|
11
|
+
raise "Book by the name #{name} was not found! Check if there was a spelling error.. or try initializing it with a book number" if hash.nil?
|
12
|
+
self.new(hash['number'])
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find string_id
|
16
|
+
hash = METADATA.find{|book| book['string_id'] == string_id}
|
17
|
+
raise "Book by the string_id #{string_id} was not found! Check if there was a spelling error.. or try initializing it with a book number" if hash.nil?
|
18
|
+
self.new(hash['number'])
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
book_hash['name']
|
23
|
+
end
|
24
|
+
|
25
|
+
def abbr_name
|
26
|
+
book_hash['abbr']
|
27
|
+
end
|
28
|
+
|
29
|
+
def number_of_chapters
|
30
|
+
book_hash['chapters'].count
|
31
|
+
end
|
32
|
+
|
33
|
+
def number
|
34
|
+
book_hash['number']
|
35
|
+
end
|
36
|
+
|
37
|
+
def first_chapter
|
38
|
+
@first_chapter ||= ScriptureChapter.new(self.number, 1)
|
39
|
+
end
|
40
|
+
|
41
|
+
def last_chapter
|
42
|
+
@last_chapter ||= ScriptureChapter.new(self.number, self.number_of_chapters)
|
43
|
+
end
|
44
|
+
|
45
|
+
def first_chapter_number
|
46
|
+
first_chapter.number
|
47
|
+
end
|
48
|
+
|
49
|
+
def last_chapter_number
|
50
|
+
last_chapter.number
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_hash
|
54
|
+
book_hash
|
55
|
+
end
|
56
|
+
|
57
|
+
def string_id
|
58
|
+
book_hash['string_id']
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def book_hash
|
64
|
+
@book_hash ||= METADATA.find{|book| book['number'] == @number.to_i}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ScriptureMeta
|
2
|
+
class ScriptureChapter
|
3
|
+
attr_accessor :scripture_book
|
4
|
+
|
5
|
+
def initialize book_number, chapter_number
|
6
|
+
@scripture_book = ScriptureBook.new(book_number)
|
7
|
+
raise ArgumentError, 'chapter number cannot be converted to an integer' unless chapter_number.respond_to?(:to_i)
|
8
|
+
raise 'book number should be within 1-66' unless (1..66).cover?(book_number.to_i)
|
9
|
+
@number = chapter_number.to_i
|
10
|
+
raise 'chapter does not exist' if chapter_hash.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
def number
|
14
|
+
chapter_hash['number']
|
15
|
+
end
|
16
|
+
|
17
|
+
def number_of_verses
|
18
|
+
chapter_hash['verses']
|
19
|
+
end
|
20
|
+
|
21
|
+
def first_verse
|
22
|
+
@first_verse = ScriptureVerse.new(scripture_book.number, self.number, 1)
|
23
|
+
end
|
24
|
+
|
25
|
+
def last_verse
|
26
|
+
@first_verse = ScriptureVerse.new(scripture_book.number, self.number, self.number_of_verses)
|
27
|
+
end
|
28
|
+
|
29
|
+
def first_verse_number
|
30
|
+
first_verse.number
|
31
|
+
end
|
32
|
+
|
33
|
+
def last_verse_number
|
34
|
+
last_verse.number
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def chapter_hash
|
40
|
+
@chapter_hash ||= @scripture_book.to_hash['chapters'].find{|chapter| chapter['number'] == @number.to_i}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module ScriptureMeta
|
2
|
+
class ScriptureReference
|
3
|
+
attr_accessor :start_verse
|
4
|
+
attr_accessor :end_verse
|
5
|
+
|
6
|
+
def initialize start_verse, end_verse
|
7
|
+
@start_verse = start_verse
|
8
|
+
@end_verse = end_verse
|
9
|
+
end
|
10
|
+
|
11
|
+
def within_same_book?
|
12
|
+
start_verse.scripture_book.number == end_verse.scripture_book.number
|
13
|
+
end
|
14
|
+
|
15
|
+
def within_same_chapter?
|
16
|
+
within_same_book? &&
|
17
|
+
start_verse.scripture_chapter.number == end_verse.scripture_chapter.number
|
18
|
+
end
|
19
|
+
|
20
|
+
def spans_entire_book?
|
21
|
+
within_same_book? &&
|
22
|
+
start_verse.scripture_chapter.number == start_verse.scripture_book.first_chapter.number &&
|
23
|
+
start_verse.number == start_verse.scripture_chapter.first_verse.number &&
|
24
|
+
end_verse.scripture_chapter.number == end_verse.scripture_book.last_chapter.number &&
|
25
|
+
end_verse.number == end_verse.scripture_chapter.last_verse.number
|
26
|
+
end
|
27
|
+
|
28
|
+
def spans_entire_chapter?
|
29
|
+
within_same_chapter? &&
|
30
|
+
start_verse.number == start_verse.scripture_chapter.first_verse.number &&
|
31
|
+
end_verse.number == end_verse.scripture_chapter.last_verse.number
|
32
|
+
end
|
33
|
+
|
34
|
+
def spans_single_verse?
|
35
|
+
within_same_chapter? &&
|
36
|
+
start_verse.number == end_verse.number
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
case
|
41
|
+
when self.spans_entire_book?
|
42
|
+
start_verse.scripture_book.name
|
43
|
+
when self.spans_entire_chapter?
|
44
|
+
"#{start_verse.scripture_book.name} #{start_verse.scripture_chapter.number}"
|
45
|
+
when self.spans_single_verse?
|
46
|
+
"#{start_verse.scripture_book.name} #{start_verse.scripture_chapter.number}:#{start_verse.number}"
|
47
|
+
when within_same_chapter?
|
48
|
+
"#{start_verse.scripture_book.name} #{start_verse.scripture_chapter.number}:#{start_verse.number}-#{end_verse.number}"
|
49
|
+
when within_same_book?
|
50
|
+
"#{start_verse.scripture_book.name} #{start_verse.scripture_chapter.number}:#{start_verse.number} - #{end_verse.scripture_chapter.number}:#{end_verse.number}"
|
51
|
+
else
|
52
|
+
"#{start_verse.scripture_book.name} #{start_verse.scripture_chapter.number}:#{start_verse.number} - #{end_verse.scripture_book.name} #{end_verse.scripture_chapter.number}:#{end_verse.number}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ScriptureMeta
|
2
|
+
class ScriptureVerse
|
3
|
+
attr_accessor :scripture_chapter
|
4
|
+
attr_accessor :number
|
5
|
+
|
6
|
+
def initialize *args
|
7
|
+
case
|
8
|
+
when args.count == 1 && args[0].is_a?(Fixnum)
|
9
|
+
raise ArgumentError, 'normalized value of scripture verse cannot be converted to an integer' unless args[0].respond_to?(:to_i)
|
10
|
+
book_number, chapter_number, verse_number = de_normalize(args[0])
|
11
|
+
when args.count == 3
|
12
|
+
book_number, chapter_number, verse_number = args
|
13
|
+
end
|
14
|
+
@scripture_chapter = ScriptureChapter.new(book_number, chapter_number)
|
15
|
+
raise ArgumentError, 'verse number cannot be converted to an integer' unless verse_number.respond_to?(:to_i)
|
16
|
+
raise 'verse number does not exist' unless (1..@scripture_chapter.number_of_verses).cover? verse_number.to_i
|
17
|
+
@number = verse_number.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def scripture_book
|
21
|
+
@scripture_chapter.scripture_book
|
22
|
+
end
|
23
|
+
|
24
|
+
def normalize
|
25
|
+
scripture_book.number * 1000000 + scripture_chapter.number * 1000 + @number
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def de_normalize number
|
31
|
+
quotient, verse_number = number.divmod(1000)
|
32
|
+
book_number, chapter_number = quotient.divmod(1000)
|
33
|
+
[book_number, chapter_number, verse_number]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/scriptura.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scriptura
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gagan Awhad
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: This is a ruby library that provides operations related with meta information
|
28
|
+
about the Bible
|
29
|
+
email:
|
30
|
+
- gagan.a.awhad@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/scriptura/data.rb
|
36
|
+
- lib/scriptura/scripture.rb
|
37
|
+
- lib/scriptura/scripture_book.rb
|
38
|
+
- lib/scriptura/scripture_chapter.rb
|
39
|
+
- lib/scriptura/scripture_reference.rb
|
40
|
+
- lib/scriptura/scripture_verse.rb
|
41
|
+
- lib/scriptura.rb
|
42
|
+
- README.md
|
43
|
+
- LICENSE
|
44
|
+
homepage: https://www.github.com/gaganawhad/scriptura
|
45
|
+
licenses: []
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.0.3
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: This is a ruby library that provides operations related with meta information
|
67
|
+
about the Bible
|
68
|
+
test_files: []
|
69
|
+
has_rdoc:
|