kjdotxml 0.1.1 → 0.2.1
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/kjdotxml.rb +91 -5
- data.tar.gz.sig +0 -0
- metadata +22 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 690ac5f8aa188410ddca62ae15087b3b5fc1dd3f04591e2f3d4b632e89160197
|
|
4
|
+
data.tar.gz: 3ce40599596b313c5c39860e1b2857a3856ff58412d9b57447447b357a18d793
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e91a9d1f12fd6eeb4c8bdd149e78b97b529c7d01fbcf90760aa4bc1e6864385972c0e1e3f3f2f8ab4152c68d5b6ec2ef7829c0be1ad7495dbe14d17d2f8f427
|
|
7
|
+
data.tar.gz: 998e8852ea26773c3ee40d72ef1acca782e64a8c162d9ab47479c001b0c8351f9bb98a9bba64f1d342e944b2a6900d2ec1867069489c46411802829decf07312
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/lib/kjdotxml.rb
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
# file: kjdotxml.rb
|
|
4
4
|
|
|
5
5
|
require 'rexle'
|
|
6
|
+
require 'abbrev'
|
|
7
|
+
require 'novowels'
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
BOOKS = [
|
|
@@ -78,16 +80,23 @@ class KjDotXmlError < Exception
|
|
|
78
80
|
end
|
|
79
81
|
|
|
80
82
|
class KjDotXml
|
|
83
|
+
|
|
84
|
+
attr_reader :booklist
|
|
81
85
|
|
|
82
|
-
def initialize(title=nil)
|
|
86
|
+
def initialize(title=nil, debug: false)
|
|
87
|
+
|
|
88
|
+
@debug = debug
|
|
89
|
+
|
|
83
90
|
book(title) if title
|
|
91
|
+
@booklist = BOOKS
|
|
92
|
+
|
|
84
93
|
end
|
|
85
94
|
|
|
86
95
|
def book(s)
|
|
87
96
|
|
|
88
97
|
filename = s.downcase.gsub(/\s/,'-') + '.xml'
|
|
89
|
-
|
|
90
|
-
filepath = File.join(File.dirname(__FILE__), '..', 'xml', filename)
|
|
98
|
+
filepath = File.join('/home/james/jamesrobertson.eu/rorb/r/ruby/kjdotxml', filename)
|
|
99
|
+
#filepath = File.join(File.dirname(__FILE__), '..', 'xml', filename)
|
|
91
100
|
|
|
92
101
|
if File.exists? filepath then
|
|
93
102
|
|
|
@@ -100,11 +109,88 @@ class KjDotXml
|
|
|
100
109
|
|
|
101
110
|
end
|
|
102
111
|
|
|
103
|
-
def books()
|
|
104
|
-
|
|
112
|
+
def books(ref=nil)
|
|
113
|
+
|
|
114
|
+
return @booklist.map {|x| books(x) } unless ref
|
|
115
|
+
|
|
116
|
+
index = ref.to_s[/^\d+$/] ? (ref.to_i - 1) : find_book(ref.downcase)
|
|
117
|
+
puts 'index: ' + index.inspect if @debug
|
|
118
|
+
|
|
119
|
+
title = @booklist[index]
|
|
120
|
+
|
|
121
|
+
|
|
105
122
|
end
|
|
123
|
+
|
|
124
|
+
def text(s)
|
|
125
|
+
|
|
126
|
+
s.strip.lines.map do |line|
|
|
127
|
+
|
|
128
|
+
[line, verses(line.chomp)]
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def verses(s)
|
|
135
|
+
|
|
136
|
+
r = s.match(/(?<book>\w+)\s+(?<chapter>\d+)[,\:]?\s*(?<verses>.*)/)
|
|
137
|
+
verses2 = r[:verses] =~ /(?:\.\.|,|-)/ ? Range.new(*r[:verses]\
|
|
138
|
+
.split(/(?:\.\.|,|-)/).map(&:to_i)).to_a : r[:verses]
|
|
139
|
+
puts 'r[:book]: ' + r[:book].inspect if @debug
|
|
140
|
+
|
|
141
|
+
doc = book(books(r[:book]))
|
|
142
|
+
|
|
143
|
+
puts 'verses2: ' + verses2.inspect if @debug
|
|
144
|
+
|
|
145
|
+
if verses2.is_a? String then
|
|
146
|
+
|
|
147
|
+
[
|
|
148
|
+
doc.root.element("chapter[@no='#{r[:chapter]}']/verse" +
|
|
149
|
+
"[@no='#{verses2}']")
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
elsif verses2.is_a? Array
|
|
153
|
+
|
|
154
|
+
verses2.map do |verse|
|
|
155
|
+
doc.root.element("chapter[@no='#{r[:chapter]}']/verse[@no='#{verse}']")
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
106
161
|
|
|
107
162
|
def to_doc()
|
|
108
163
|
@doc
|
|
109
164
|
end
|
|
165
|
+
|
|
166
|
+
private
|
|
167
|
+
|
|
168
|
+
def find_book(ref)
|
|
169
|
+
|
|
170
|
+
puts 'find_book/ref: ' + ref.inspect if @debug
|
|
171
|
+
|
|
172
|
+
h = @booklist.inject({}) do |r,rawx|
|
|
173
|
+
|
|
174
|
+
x = rawx.downcase
|
|
175
|
+
a3 = [
|
|
176
|
+
x,
|
|
177
|
+
x.sub(/(\d)\s/,'\1'),
|
|
178
|
+
x.sub(/(\d)\s/,'\1-'),
|
|
179
|
+
NoVowels.compact(x),
|
|
180
|
+
NoVowels.compact(x.sub(/(\d)\s/,'\1')),
|
|
181
|
+
NoVowels.compact(x.sub(/(\d)\s/,'\1-')),
|
|
182
|
+
]
|
|
183
|
+
#puts 'a3: ' + a3.inspect if @debug
|
|
184
|
+
a3b = a3.uniq.abbrev.keys.reject {|x| x[/^\s*\d+$/] or x.length < 2}
|
|
185
|
+
r.merge(rawx => a3b)
|
|
186
|
+
|
|
187
|
+
end
|
|
188
|
+
#puts 'h: ' + h.inspect if @debug
|
|
189
|
+
r = h.find {|key, val| val.grep(/#{ref}/).any? }
|
|
190
|
+
r = h.find {|key, vl| vl.grep(/#{ref.sub(/\d+\s*/,'')}/).any? } unless r
|
|
191
|
+
puts '_r: ' + r.inspect if @debug
|
|
192
|
+
@booklist.index r.first if r
|
|
193
|
+
|
|
194
|
+
end
|
|
195
|
+
|
|
110
196
|
end
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kjdotxml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Robertson
|
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
|
36
36
|
OXTrn4UmSRUyQHWNI24lThlPaWZJ6ULj4BtuALPaaM/cWYRhRaE3NiLF/SFiyzGg
|
|
37
37
|
JYoHu6HVj1QoC6XZVMnuByx8sBhH1e/kRkk=
|
|
38
38
|
-----END CERTIFICATE-----
|
|
39
|
-
date: 2022-11-
|
|
39
|
+
date: 2022-11-03 00:00:00.000000000 Z
|
|
40
40
|
dependencies:
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rexle
|
|
@@ -58,6 +58,26 @@ dependencies:
|
|
|
58
58
|
- - ">="
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
60
|
version: 1.5.14
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: novowels
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0.1'
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: 0.1.3
|
|
71
|
+
type: :runtime
|
|
72
|
+
prerelease: false
|
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
74
|
+
requirements:
|
|
75
|
+
- - "~>"
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0.1'
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: 0.1.3
|
|
61
81
|
description:
|
|
62
82
|
email: digital.robertson@gmail.com
|
|
63
83
|
executables: []
|
metadata.gz.sig
CHANGED
|
Binary file
|