kj 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 391f9d2ad20e44f0ca583f941d20bcbed1adf68a
4
- data.tar.gz: f0af5e6cf11e617365526ec12a7f6087f7544d58
3
+ metadata.gz: 8a9f1ae7069ea9589316a04b3fdab9c7ebc66330
4
+ data.tar.gz: 9409e75e89768a71a76229b561737ab40f3ab44b
5
5
  SHA512:
6
- metadata.gz: 64cd538cfc96c9e165247ac12cc3f96d20bd14ecbfc2b4a4f16aeae1b26e557d28aa0d48faa1ca21130d053fed422879d26074c54757a4490067c503d3d363c6
7
- data.tar.gz: 589de22bcea83755b32fb17a4a80f9658d7684686ef791180372544c1c93301ed0cc8be5b5dab51f713c720f12d8b7f0ce7c497435c2e549b0bfa82697b153cd
6
+ metadata.gz: 2be24a33435f0329e246eee2d01334e8e2ecdb0934e6fedade4fb7704f1e1f21d4502043e559abe9d12468e478be90976ea5a301365d0e9ee1eda16eb98f4a5a
7
+ data.tar.gz: ad8b9ae4438462a8da3133d74fe3cb6f7ccc391ec221b131e47d9b610bd8815e9d63d1ee84f95d6f3267ef5c75b0023947f5fbbc9b165c1e6ffd6d2b05f717fe
data/README.md CHANGED
@@ -67,6 +67,7 @@ puts verse.text
67
67
  verse.next # returns the next Verse
68
68
  verse.prev # returns the previous Verse
69
69
  ```
70
+ ## Other Stuff
70
71
  ### Random
71
72
  ```ruby
72
73
  bible.random_book #returns a random Kj::Book
@@ -82,6 +83,13 @@ verse = bible.percent(0.5)
82
83
  puts verse.title
83
84
  => "Psalms 103:1"
84
85
  ```
86
+ ### Pages
87
+ ```ruby
88
+ # Locate Verse objects for a particular page (1-1609)
89
+ verses = bible.page(777)
90
+ puts verses.first.title
91
+ => "Psalms 22:26"
92
+ ```
85
93
  ### Exceptions
86
94
  Kj will raise a Kj::Iniquity when it can't find what you're looking for.
87
95
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.14
1
+ 0.0.15
data/db/kjb.db CHANGED
Binary file
data/kj.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: kj 0.0.14 ruby lib
5
+ # stub: kj 0.0.15 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "kj"
9
- s.version = "0.0.14"
9
+ s.version = "0.0.15"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["David John"]
14
- s.date = "2015-08-09"
14
+ s.date = "2015-08-11"
15
15
  s.description = "kj is a simple rubygem for accessing the King James Bible. It uses an embedded sqlite data store."
16
16
  s.email = "djohn@arch-no.org"
17
17
  s.extra_rdoc_files = [
data/lib/kj.rb CHANGED
@@ -30,6 +30,14 @@ module Kj
30
30
  Verse.at(percent)
31
31
  end
32
32
 
33
+ def page(page)
34
+ Verse.page(page)
35
+ end
36
+
37
+ def self.page_count
38
+ Verse.page_count
39
+ end
40
+
33
41
  end
34
42
 
35
43
  end
@@ -22,8 +22,8 @@ module Kj
22
22
  end
23
23
 
24
24
  def self.random
25
- verse = Db.query("SELECT id, chapter_id, number FROM verses WHERE id = ?", [rand(1..count)], true)
26
- new(id: verse['id'], chapter_id: verse['chapter_id'], number: verse['number'])
25
+ verse = Db.query("SELECT id, chapter_id, number, page FROM verses WHERE id = ?", [rand(1..count)], true)
26
+ new(id: verse['id'], chapter_id: verse['chapter_id'], number: verse['number'], page: verse['page'])
27
27
  end
28
28
 
29
29
  def self.percent(decimal)
@@ -34,8 +34,17 @@ module Kj
34
34
  else
35
35
  verse_id = (count * decimal).round
36
36
  end
37
- verse = Db.query("SELECT id, chapter_id, number FROM verses WHERE id = ?", [verse_id], true)
38
- new(id: verse['id'], chapter_id: verse['chapter_id'], number: verse['number'])
37
+ verse = Db.query("SELECT id, chapter_id, number, page FROM verses WHERE id = ?", [verse_id], true)
38
+ new(id: verse['id'], chapter_id: verse['chapter_id'], number: verse['number'], page: verse['page'])
39
+ end
40
+
41
+ def self.page_count
42
+ 1609
43
+ end
44
+
45
+ def self.page(page)
46
+ verses = Db.query("SELECT id, chapter_id, number, page FROM verses WHERE page = ?", [page])
47
+ verses.map{|verse| new(id: verse['id'], chapter_id: verse['chapter_id'], number: verse['number'], page: verse['page'])}
39
48
  end
40
49
 
41
50
  def chapter
@@ -63,31 +72,38 @@ module Kj
63
72
 
64
73
  def next
65
74
  @next ||= begin
66
- v = Db.query("SELECT id, chapter_id, text, number FROM verses WHERE id = ?", [id + 1], true)
67
- self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'])
75
+ v = Db.query("SELECT id, chapter_id, text, number, page FROM verses WHERE id = ?", [id + 1], true)
76
+ self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'], page: v['page'])
68
77
  rescue Kj::Iniquity
69
- v = Db.query("SELECT id, chapter_id, text, number FROM verses WHERE id = ?", [1], true)
70
- self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'])
78
+ v = Db.query("SELECT id, chapter_id, text, number, page FROM verses WHERE id = ?", [1], true)
79
+ self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'], page: v['page'])
71
80
  end
72
81
  end
73
82
 
74
83
  def prev
75
84
  @prev ||= begin
76
- v = Db.query("SELECT id, chapter_id, text, number FROM verses WHERE id = ?", [id - 1], true)
77
- self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'])
85
+ v = Db.query("SELECT id, chapter_id, text, number, page FROM verses WHERE id = ?", [id - 1], true)
86
+ self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'], page: v['page'])
78
87
  rescue Kj::Iniquity
79
- v = Db.query("SELECT id, chapter_id, text, number FROM verses WHERE id = ?", [self.class.count], true)
80
- self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'])
88
+ v = Db.query("SELECT id, chapter_id, text, number, page FROM verses WHERE id = ?", [self.class.count], true)
89
+ self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'], page: v['page'])
81
90
  end
82
91
  end
83
92
 
84
93
  def text
85
94
  @text ||= begin
86
- verse = Db.query("SELECT chapter_id, text FROM verses WHERE id = ?", [id], true)
95
+ verse = Db.query("SELECT text FROM verses WHERE id = ?", [id], true)
87
96
  verse['text']
88
97
  end
89
98
  end
90
99
 
100
+ def page
101
+ @page ||= begin
102
+ verse = Db.query("SELECT page FROM verses WHERE id = ?", [id], true)
103
+ verse['page']
104
+ end
105
+ end
106
+
91
107
  end
92
108
 
93
109
  end
@@ -48,6 +48,12 @@ describe "Kj" do
48
48
  end
49
49
  end
50
50
 
51
+ describe '.page' do
52
+ it 'returns the verses for the page' do
53
+ expect(Kj::Verse.page(1).length).to eq(21)
54
+ end
55
+ end
56
+
51
57
  end
52
58
 
53
59
  end
@@ -21,23 +21,32 @@ csv.each do |row| # build books table
21
21
  end
22
22
 
23
23
  current_book_id, current_book_name, current_chapter_id, current_chapter_number = nil, nil, nil, nil # import chapters, verses
24
+ current_page, current_word_count = 0, 0
24
25
  File.readlines(File.join(path.parent.to_s, 'kjb.txt')).each do |line| #obtained from https://getbible.net/Bibles
25
26
  parts = line.split('||')
26
27
  book_name = parts[0]
27
28
  chapter_number = parts[1].to_i
28
29
  verse_number = parts[2].to_i
29
30
  verse_text = parts[3].chomp
31
+ current_word_count += verse_text.split.length
32
+
30
33
  if current_book_name != book_name
31
34
  current_book_name = book_name
32
35
  current_chapter_number = nil
36
+ current_word_count = 0
37
+ current_page += 1
33
38
  current_book_id = db.get_first_row("SELECT id FROM books WHERE name = ?", [book_name])['id']
39
+ elsif current_word_count > 485
40
+ current_word_count = 0
41
+ current_page += 1
34
42
  end
43
+
35
44
  if current_chapter_number != chapter_number
36
45
  current_chapter_number = chapter_number
37
46
  db.execute("INSERT INTO chapters(number, book_id) VALUES (?, ?)", [chapter_number, current_book_id])
38
47
  current_chapter_id = db.last_insert_row_id
39
48
  end
40
- db.execute("INSERT INTO verses(text, number, chapter_id) VALUES (?, ?, ?)", [verse_text, verse_number, current_chapter_id])
49
+ db.execute("INSERT INTO verses(text, number, chapter_id, page) VALUES (?, ?, ?, ?)", [verse_text, verse_number, current_chapter_id, current_page])
41
50
  end
42
51
 
43
52
  db.close
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - David John
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-09 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3