kjlite 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: e3b7c46a571806088c53a2f65b4508ca36790b42251b01b45c3a01093618d4f4
4
- data.tar.gz: 7fe517ce5e056f3fa39c3bd2dc1cb846b7f76244f846f278b5764075b423adff
3
+ metadata.gz: d9828f3ba1ba9e27da83bdd6f1bf8d9c68736fc716ad520201a4c97d3cd47003
4
+ data.tar.gz: 62e27f180ddf0603f06352ebef55495314fec8fe8e095ca950ea9ee035d5d7f0
5
5
  SHA512:
6
- metadata.gz: 3c86cf1f4dd834ae89c77298c7e00f9609f1cea76d00778b217560f91369ca5046e649bcb53ca99a938a0170cccf01af4ed7e981887d0a27ce4d71dfdd266630
7
- data.tar.gz: c754626e80e48866c3156c7034cf15d8ba00c8b99749055e03de3052fb21bf0723b82c2cdc11a30981f15afe9a87dcb497a4e1c575d5061230c1edd0cbb9789d
6
+ metadata.gz: 43cc29791deeea09d3f4eefc64c150b545d6821f3e47e84089b999e0a8079e1992f2c69b536d9779e2f6a11c21fd0a2e09057a3eaa43cfb8cbb882bdf662de74
7
+ data.tar.gz: b4b72cb2da6d3a5871eceb7824654d53b57ca677d56aa21f89502d04882a4c1bc17e0b6002dbb6de3be81494ad99ec347ccb1ddd896765d611d44da7f68b65a1
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/kjlite.rb CHANGED
@@ -19,12 +19,12 @@ module KjLite
19
19
  end
20
20
 
21
21
  def inspect()
22
- "#<KjLite::Verse @book_name=#{@book_name} " +
22
+ "#<KjLite::Verse @book_name=#{@book_name} " +
23
23
  "@chapter_id=#{@chapter_id} @number=#{@number}>"
24
24
  end
25
25
 
26
26
  def text()
27
- @verse[/^\d+:\d+:\d+\s+(.*)/m,1].gsub(/[\r\n]|\s\s/,'')
27
+ @verse[/^\d+:\d+:\d+\s+(.*)/m,1].gsub(/[\r\n\s]+/,' ').rstrip
28
28
  end
29
29
 
30
30
  def title()
@@ -53,15 +53,19 @@ module KjLite
53
53
  def verses(*list)
54
54
 
55
55
  puts 'inside verses' if @debug
56
-
56
+ puts '@verses: ' + @verses.inspect if @debug
57
+
57
58
  list = list.first.to_a if list.first.is_a? Range
58
59
 
59
60
  if list.empty? then
60
- return @verses.map.with_index {|x,i| Verse.new @book_name, @id, i+1, x}
61
+ return @verses.map.with_index do |x,i|
62
+ #puts 'x: ' + x.inspect
63
+ Verse.new @book_name, @id, i+1, x, debug: @debug
64
+ end
61
65
  elsif list.length < 2
62
66
  Verse.new @book_name, @id, list.first, @verses[list.first.to_i-1]
63
67
  else
64
- list.flatten.map do |n|
68
+ list.flatten.map do |n|
65
69
  Verse.new @book_name, @id, n, @verses[n.to_i-1]
66
70
  end
67
71
  end
@@ -85,7 +89,7 @@ module KjLite
85
89
  class Book
86
90
 
87
91
  attr_reader :id, :name, :permalink
88
-
92
+
89
93
  def initialize(id, name, chapters, debug: false)
90
94
 
91
95
  @id, @name, @debug = id, name, debug
@@ -103,7 +107,7 @@ module KjLite
103
107
 
104
108
  def chapters(*args)
105
109
 
106
- puts 'args: ' + args.inspect if @debug
110
+ puts 'args: ' + args.inspect if @debug
107
111
 
108
112
  if args.empty? then
109
113
  return @chapters
@@ -112,7 +116,7 @@ module KjLite
112
116
  else
113
117
  args.flatten.map {|n| @chapters[n-1] }.compact
114
118
  end
115
-
119
+
116
120
  end
117
121
 
118
122
  def inspect()
@@ -131,7 +135,7 @@ module KjLite
131
135
 
132
136
  def initialize(url='https://gutenberg.org/cache/epub/30/pg30.txt',
133
137
  debug: false)
134
-
138
+
135
139
  filename, @debug = 'kjbible.txt', debug
136
140
 
137
141
  if File.exists?(filename) then
@@ -144,44 +148,42 @@ module KjLite
144
148
  s2 = s.split(/.*(?=^Book 01)/,3).last; 0
145
149
  a = s2.split(/.*(?=^Book \d+)/); 0
146
150
 
147
- h = a.inject({}) do |r,x|
151
+ @h = a.inject({}) do |r,x|
148
152
 
149
153
  title, body = x.match(/^Book \d+\s+([^\r]+)\s+(.*)/m).captures
150
154
 
151
155
  a2 = body.split(/.*(?=\d+\:\d+\:\d+)/)
152
156
  a3 = a2.group_by {|x| x[/^\d+:\d+/]}.to_a.map(&:last)
153
- r.merge(title => a3[1..-1])
157
+ r.merge(title => a3[1..-1])
154
158
 
155
159
  end
156
-
160
+
161
+ #puts '@h: ' + @h.keys.inspect
162
+ =begin
157
163
  @h = h.group_by {|key, _| key[/\d*\s*(.*)/,1]}; 0
158
164
 
159
165
  @h.each do |key, value|
160
166
  @h[key] = value.length < 2 ? value.last.last : value.map(&:last)
161
167
  end
162
-
163
- @to_h, @to_s, @booklist = @h, s, h.keys
168
+ =end
169
+ @to_h, @to_s, @booklist = @h, s, @h.keys
164
170
 
165
171
  end
166
172
 
167
- def books(ref=nil)
168
-
173
+ def books(ref=nil)
174
+
169
175
  return @booklist.map {|x| books(x) } unless ref
170
176
 
171
177
  index = ref.to_s[/^\d+$/] ? (ref.to_i - 1) : find_book(ref.downcase)
172
178
  puts 'index: ' + index.inspect if @debug
173
179
  title = @booklist[index]
174
- r = @h[title.sub(/^\d+\s+/,'')]
180
+ #r = @h[title.sub(/^\d+\s+/,'')]
181
+ r = @h[title]
175
182
 
176
183
  puts 'r: ' + r.class.inspect if @debug
177
184
 
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
+ Book.new index+1, title, r, debug: @debug
186
+
185
187
  end
186
188
 
187
189
  def inspect()
@@ -204,6 +206,8 @@ module KjLite
204
206
 
205
207
  def find_book(ref)
206
208
 
209
+ puts 'find_book/ref: ' + ref.inspect if @debug
210
+
207
211
  h = @booklist.inject({}) do |r,rawx|
208
212
 
209
213
  x = rawx.downcase
@@ -215,16 +219,16 @@ module KjLite
215
219
  NoVowels.compact(x.sub(/(\d)\s/,'\1')),
216
220
  NoVowels.compact(x.sub(/(\d)\s/,'\1-')),
217
221
  ]
218
- puts 'a3: ' + a3.inspect if @debug
222
+ #puts 'a3: ' + a3.inspect if @debug
219
223
  a3b = a3.uniq.abbrev.keys.reject {|x| x[/^\s*\d+$/] or x.length < 2}
220
224
  r.merge(rawx => a3b)
221
225
 
222
226
  end
223
- puts 'h: ' + h.inspect if @debug
227
+ #puts 'h: ' + h.inspect if @debug
224
228
  r = h.find {|key, val| val.grep(/#{ref}/).any? }
225
229
  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
230
+ puts '_r: ' + r.inspect if @debug
231
+ @booklist.index r.first if r
228
232
 
229
233
  end
230
234
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kjlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -36,7 +36,7 @@ cert_chain:
36
36
  EALnBk6AgDlRDIbN+5DYzhfnTJ1Tjl8AktYuDKy5QnljJI1ywXdnUUQV4sbSUiIq
37
37
  GLSnE26JTgh8Vx2YqZ7IisLxAR/yR2wdAG8=
38
38
  -----END CERTIFICATE-----
39
- date: 2022-07-14 00:00:00.000000000 Z
39
+ date: 2022-10-31 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: novowels
metadata.gz.sig CHANGED
Binary file