kjlite 0.1.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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -0
  4. data/lib/kjlite.rb +234 -0
  5. metadata +91 -0
  6. metadata.gz.sig +4 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5cde0f8d3eddc5f53ac438664f8429ccb1ac40b98264a5bb362dcb468b8572f
4
+ data.tar.gz: 556f581983938d18ac256f622485ebab6a22c98692221460288032e96067a931
5
+ SHA512:
6
+ metadata.gz: 8c26d4b31d50b8b52e627e933b2bb67ef7c7fb60c67eae09ed8b00b3683b1523be5dd1250e62dfa4293ab1af86891d31f560c94bb2b2a9e2bedaf698e82d6a12
7
+ data.tar.gz: 891e58b74defaeca770ce2bbaeed0cc6222741e19584b650e14633d03afb5bf8e0d316c4c57db6bdf55c24c1746b58c829d1881cbb2bd45281238c551828b628
Binary file
@@ -0,0 +1 @@
1
+ &՚¹��x�Ҙ��'����1X�*�����_�{}i0���E C_>��1������rï��G ��'�C�{T�!h�ͦv�=|M��h�'��=fn���sKX��ܸ��_��է�������S��Yr���‘l�Lti`�I��1ؖ���kͤ �0_����z �;�|�������?M|� �#�7U�+�Tޱ�q���/W!����0<e��#�+�Bo���1���S3
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: kjlite.rb
4
+
5
+ require 'abbrev'
6
+ require 'novowels'
7
+ require 'open-uri'
8
+
9
+
10
+ module KjLite
11
+
12
+ class Verse
13
+
14
+ attr_reader :book_id, :chapter_id, :number
15
+
16
+ def initialize(book_name, chapter_id, number, verse, debug: false)
17
+ @book_name, @chapter_id, @debug = book_name, chapter_id, debug
18
+ @number, @verse = number, verse
19
+ end
20
+
21
+ def inspect()
22
+ "#<KjLite::Verse @book_name=#{@book_name} " +
23
+ "@chapter_id=#{@chapter_id} @number=#{@number}>"
24
+ end
25
+
26
+ def text()
27
+ @verse[/^\d+:\d+:\d+\s+(.*)/m,1].gsub(/[\r\n]|\s\s/,'')
28
+ end
29
+
30
+ def title()
31
+ "%s %s:%s" % [@book_name, @chapter_id, @number]
32
+ end
33
+
34
+ def to_s()
35
+ @verse
36
+ end
37
+
38
+ end
39
+
40
+ class Chapter
41
+
42
+ attr_reader :id, :book_id, :number, :title
43
+
44
+ def initialize(allverses, id, book_id, book_name, debug: false)
45
+ @verses, @id, @book_id, @debug = allverses, id, book_id, debug
46
+ @book_name = book_name
47
+ end
48
+
49
+ def verse(n)
50
+ verses(n).text
51
+ end
52
+
53
+ def verses(*list)
54
+
55
+ puts 'inside verses' if @debug
56
+
57
+ list = list.first.to_a if list.first.is_a? Range
58
+
59
+ if list.empty? then
60
+ return @verses.map.with_index {|x,i| Verse.new @book_name, @id, i+1, x}
61
+ elsif list.length < 2
62
+ Verse.new @book_name, @id, list.first, @verses[list.first.to_i-1]
63
+ else
64
+ list.flatten.map do |n|
65
+ Verse.new @book_name, @id, n, @verses[n.to_i-1]
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ def inspect()
72
+ "#<KjLite::Chapter @id=#{@id} @book_id=#{@book_id} @number=#{@id}>"
73
+ end
74
+
75
+ def title()
76
+ "%s %s" % [@book_name, @id]
77
+ end
78
+
79
+ def to_s()
80
+ title()
81
+ end
82
+
83
+ end
84
+
85
+ class Book
86
+
87
+ attr_reader :id, :name, :permalink
88
+
89
+ def initialize(id, name, chapters, debug: false)
90
+
91
+ @id, @name, @debug = id, name, debug
92
+ @permalink = name.downcase.gsub(/\s/,'-')
93
+ puts 'chapters.length : ' + chapters.length.inspect if @debug
94
+ @chapters = chapters.map.with_index do |x,i|
95
+ Chapter.new x, i+1, id, name, debug: @debug
96
+ end
97
+
98
+ end
99
+
100
+ def chapter(n)
101
+ chapters n
102
+ end
103
+
104
+ def chapters(*args)
105
+
106
+ puts 'args: ' + args.inspect if @debug
107
+
108
+ if args.empty? then
109
+ return @chapters
110
+ elsif args.length < 2
111
+ @chapters[args.first.to_i-1]
112
+ else
113
+ args.flatten.map {|n| @chapters[n-1] }.compact
114
+ end
115
+
116
+ end
117
+
118
+ def inspect()
119
+ "#<KjLite::Book @name=#{@name.inspect} @chapters=#{@chapters.inspect}>"
120
+ end
121
+
122
+ def to_s()
123
+ @chapters
124
+ end
125
+
126
+ end
127
+
128
+ class Bible
129
+
130
+ attr_reader :to_h, :to_s, :booklist
131
+
132
+ def initialize(url='http://www.gutenberg.org/cache/epub/30/pg30.txt',
133
+ debug: false)
134
+
135
+ filename, @debug = 'kjbible.txt', debug
136
+
137
+ if File.exists?(filename) then
138
+ s = File.read(filename)
139
+ else
140
+ s = open(url).read
141
+ File.write filename, s
142
+ end
143
+
144
+ s2 = s.split(/.*(?=^Book 01)/,3).last; 0
145
+ a = s2.split(/.*(?=^Book \d+)/); 0
146
+
147
+ h = a.inject({}) do |r,x|
148
+
149
+ title, body = x.match(/^Book \d+\s+([^\r]+)\s+(.*)/m).captures
150
+
151
+ a2 = body.split(/.*(?=\d+\:\d+\:\d+)/)
152
+ a3 = a2.group_by {|x| x[/^\d+:\d+/]}.to_a.map(&:last)
153
+ r.merge(title => a3[1..-1])
154
+
155
+ end
156
+
157
+ @h = h.group_by {|key, _| key[/\d*\s*(.*)/,1]}; 0
158
+
159
+ @h.each do |key, value|
160
+ @h[key] = value.length < 2 ? value.last.last : value.map(&:last)
161
+ end
162
+
163
+ @to_h, @to_s, @booklist = @h, s, h.keys
164
+
165
+ end
166
+
167
+ def books(ref=nil)
168
+
169
+ return @booklist.map {|x| books(x) } unless ref
170
+
171
+ index = ref.to_s[/^\d+$/] ? (ref.to_i - 1) : find_book(ref.downcase)
172
+ puts 'index: ' + index.inspect if @debug
173
+ title = @booklist[index]
174
+ r = @h[title.sub(/^\d+\s+/,'')]
175
+
176
+ puts 'r: ' + r.class.inspect if @debug
177
+
178
+ if r.length > 3 then
179
+ Book.new index+1, title, r, debug: @debug
180
+ else
181
+ i = ref[/\d+/].to_i - 1
182
+ a = r.map.with_index {|x,i| Book.new index+1, title, r[i], debug: @debug}
183
+ a[i]
184
+ end
185
+ end
186
+
187
+ def inspect()
188
+ "#<KjLite::Bible @booklist=#{@booklist}>"
189
+ end
190
+
191
+ def random_book()
192
+ books booklist.sample
193
+ end
194
+
195
+ def random_chapter()
196
+ random_book.chapters.sample
197
+ end
198
+
199
+ def random_verse()
200
+ random_chapter.verses.sample
201
+ end
202
+
203
+ private
204
+
205
+ def find_book(ref)
206
+
207
+ h = @booklist.inject({}) do |r,rawx|
208
+
209
+ x = rawx.downcase
210
+ a3 = [
211
+ x,
212
+ x.sub(/(\d)\s/,'\1'),
213
+ x.sub(/(\d)\s/,'\1-'),
214
+ NoVowels.compact(x),
215
+ NoVowels.compact(x.sub(/(\d)\s/,'\1')),
216
+ NoVowels.compact(x.sub(/(\d)\s/,'\1-')),
217
+ ]
218
+ puts 'a3: ' + a3.inspect if @debug
219
+ a3b = a3.uniq.abbrev.keys.reject {|x| x[/^\s*\d+$/] or x.length < 2}
220
+ r.merge(rawx => a3b)
221
+
222
+ end
223
+ puts 'h: ' + h.inspect if @debug
224
+ r = h.find {|key, val| val.grep(/#{ref}/).any? }
225
+ r = h.find {|key, vl| vl.grep(/#{ref.sub(/\d+\s*/,'')}/).any? } unless r
226
+ puts 'r: ' + r.inspect if @debug
227
+ @booklist.index r.first
228
+
229
+ end
230
+
231
+ end
232
+
233
+ end
234
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kjlite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0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m20nqrT8yZzj8C7QU+IPO2lXX
30
+ BHiaMWsxZm0hl7D5wjxTbO8z07KNZezXaecCqTYVIJ77HABB8EUedZSbvsDkS+16
31
+ F3JJvL6yz2nKMSnIXdddSz09NVA3CGp5xtgUCK3rxaI70fDIxhdoxcMeriImnF/k
32
+ BtVMP6sCY7YgHeGEqvvX6JrRoTq5IXOgURufKe+UYEe2h6r7MVxB6EX99PnDjQe9
33
+ mpk8pHkDTiOsamwzdRl5g1utCWoEGGcR5RdDDXkGIHPZfpKSo63Ci+3x4s6PMcOy
34
+ nH689Sdw5mNWuIhVvszKA+jrCHbqMrrPUuRR8QBGl7dtDw3CIbN1SzGrG9qSTaE4
35
+ 7Gcy8IrLOPU1HEKZKt+vY47mSWAUSe+4nwxccGZyHJtZtFdnPtvDyuAjH2+u4T2k
36
+ Dr1Vid3kU5/7VH1UBV1RZs5P
37
+ -----END CERTIFICATE-----
38
+ date: 2019-11-10 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: novowels
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.1'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.1.3
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.1'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.1.3
60
+ description:
61
+ email: james@jamesrobertson.eu
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - lib/kjlite.rb
67
+ homepage: https://github.com/jrobertson/kjlite
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.0.3
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: kjlist is a lightweight version of the kj gem for accessing the King James
90
+ Bible. It downloads the text file from gutenberg.org.
91
+ test_files: []
@@ -0,0 +1,4 @@
1
+ ��BȄ����0ݦq���]�?����{x.����ԃ�v5���w ��"��~1*�\��I6*�׿�6P�qڕ� ��<�� �5��[�`�m�d� ��6���C6�*�7S{觕6UǬ3T1c�0�������o{��Cj�[��g>u3���v �)��D�
2
+ 4@M�T���~�'v���*���\tQ$�? R�3}~6��O�q0Sc��F7�w��� ���*8�gԗ�
3
+ �՘Kx#o��G����'Bx�f�I�%4�33�cZ�@��o����:t����^fh
4
+ ���F��q���)��T������6�g��SfnX�E��@