sqlbible 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/sqlbible +24 -14
- data/lib/sqlbible/version.rb +1 -1
- data/lib/sqlbible.rb +22 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b620e9b57b9ffdc57b71231b5a6bfb0619dd196dd99428a4f3ab71d682f60b72
|
4
|
+
data.tar.gz: 196e6a8907ab5b90adce9d9d2c935593796e9b86eb6b7d362a0ca419436b76ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ac874cb85c60996f406f522f6d010e9e6c07c950b10ed1d9783a87ac936bc1ddc8123dc382ae92298e15382962faed773c2b43b4e6a35e4787e06a3183c5e58
|
7
|
+
data.tar.gz: 927964e349b1e54f5156b3e994ef704411ed5845a0c7c13edabe175170a2d759801525438e1459c76598100159f7e7b8b07d13f39f6043edc5872f71bfa22261
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ bible = Sqlbible.new('kjv.sqlite')
|
|
19
19
|
# simple search
|
20
20
|
bible.search(/Jesus/)
|
21
21
|
|
22
|
-
# Sqlbible is designed to
|
22
|
+
# Sqlbible is designed to work well with Scripref references and passages
|
23
23
|
require 'scripref'
|
24
24
|
|
25
25
|
# define a reference for the gospels
|
data/bin/sqlbible
CHANGED
@@ -7,17 +7,20 @@ require 'scripref'
|
|
7
7
|
require 'sqlbible'
|
8
8
|
|
9
9
|
result = OptimistXL.options do
|
10
|
-
synopsis 'Usage:
|
10
|
+
synopsis 'Usage: sqlbible [options] [<command> [suboptions] <filename>]'
|
11
11
|
subcmd :convert, 'Convert a bible from OSIS-XML to Sqlbible format' do
|
12
|
-
opt :
|
12
|
+
opt :name, 'Name of the converted bible module or output filename of the generated .sqlbible file', type: String, required: true
|
13
|
+
opt :overwrite, 'Overwrite existing module or output file if exist', type: :Boolean, default: false
|
13
14
|
end
|
14
15
|
subcmd :search, 'Search with regular expressions' do
|
16
|
+
opt :name, 'Name of the bible module filename of an .sqlbible file', type: String
|
15
17
|
opt :search, 'Regular expression to search (multiple allowed)', type: String, multi: true, required: true
|
16
18
|
opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: 'en'
|
17
19
|
opt :output, 'Output filename', type: String
|
18
20
|
opt :range, 'Search range, example: "John 1-10"', type: String
|
19
21
|
end
|
20
22
|
subcmd :text, 'Show text of references' do
|
23
|
+
opt :name, 'Name of the bible module filename of an .sqlbible file', type: String
|
21
24
|
opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: 'en'
|
22
25
|
opt :output, 'Output filename', type: String
|
23
26
|
opt :reference, 'Reference to show, example: "John 3:16; 10:27-30"', type: String, required: true
|
@@ -25,11 +28,6 @@ result = OptimistXL.options do
|
|
25
28
|
version format("sqlbible %s\nschema version %s", Sqlbible::VERSION, Sqlbible.schema_version)
|
26
29
|
end
|
27
30
|
|
28
|
-
unless filename = result.leftovers.first
|
29
|
-
$stderr.puts 'no filename given'
|
30
|
-
exit 1
|
31
|
-
end
|
32
|
-
|
33
31
|
def determine_lang_mod subopts
|
34
32
|
case l = subopts[:lang]
|
35
33
|
when 'en', nil
|
@@ -57,13 +55,25 @@ subopts = result.subcommand_options
|
|
57
55
|
|
58
56
|
case result.subcommand
|
59
57
|
when 'convert'
|
58
|
+
require 'fileutils'
|
60
59
|
require 'sqlbible/convert'
|
61
|
-
osis_fn =
|
62
|
-
|
60
|
+
unless osis_fn = result.leftovers.first
|
61
|
+
$stderr.puts 'no filename given'
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
sqlbible_fn = Sqlbible.resolve_db_filename(subopts[:name])
|
65
|
+
if !subopts[:overwrite] && File.exist?(sqlbible_fn)
|
66
|
+
$stderr.puts format('file %s exist, conversion aborted', sqlbible_fn)
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
unless File.exist?(dir = Sqlbible.bibles_dir)
|
70
|
+
puts format('create directory %s', dir)
|
71
|
+
FileUtils.mkdir_p dir
|
72
|
+
end
|
63
73
|
if $stdout.tty?
|
64
|
-
puts "convert #{osis_fn} to #{
|
74
|
+
puts "convert #{osis_fn} to #{sqlbible_fn} ..."
|
65
75
|
end
|
66
|
-
Sqlbible.convert osis_fn,
|
76
|
+
Sqlbible.convert osis_fn, sqlbible_fn
|
67
77
|
exit
|
68
78
|
when 'search'
|
69
79
|
searches = subopts[:search]
|
@@ -74,8 +84,8 @@ when 'search'
|
|
74
84
|
else
|
75
85
|
range = nil
|
76
86
|
end
|
77
|
-
out = determine_out
|
78
|
-
bible = Sqlbible.new(
|
87
|
+
out = determine_out(subopts)
|
88
|
+
bible = Sqlbible.new(subopts[:name])
|
79
89
|
regexes = searches.map {|s| Regexp.new(s)}
|
80
90
|
f = Scripref::Formatter.new(lang_mod, bookformat: :abbrev)
|
81
91
|
bible.search(regexes, range: range).each do |v|
|
@@ -86,7 +96,7 @@ when 'text'
|
|
86
96
|
p = Scripref::Parser.new(lang_mod)
|
87
97
|
f = Scripref::Formatter.new(lang_mod, bookformat: :abbrev)
|
88
98
|
ref = p.parse(subopts[:reference])
|
89
|
-
bible = Sqlbible.new(
|
99
|
+
bible = Sqlbible.new(subopts[:name])
|
90
100
|
out = determine_out subopts
|
91
101
|
bible.reference(ref).flatten.each do |v|
|
92
102
|
out.puts format_verse(f, v)
|
data/lib/sqlbible/version.rb
CHANGED
data/lib/sqlbible.rb
CHANGED
@@ -8,8 +8,14 @@ require_relative 'sqlbible/version'
|
|
8
8
|
|
9
9
|
class Sqlbible
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
attr_reader :db_filename
|
12
|
+
|
13
|
+
def initialize db_name
|
14
|
+
@db_filename = Sqlbible.resolve_db_filename(db_name)
|
15
|
+
unless File.exist? @db_filename
|
16
|
+
fail ArgumentError, format('database %s not found, file %s does not exist', db_name, @db_filename)
|
17
|
+
end
|
18
|
+
@db = SQLite3::Database.new(@db_filename)
|
13
19
|
@db.enable_load_extension(true)
|
14
20
|
pcre_extension_file = ENV['SQLITE_PCRE_EXTENSION']
|
15
21
|
@db.load_extension(pcre_extension_file) if pcre_extension_file
|
@@ -37,7 +43,7 @@ class Sqlbible
|
|
37
43
|
if range
|
38
44
|
passages = Array(range).select {|e| e.kind_of? Scripref::Passage}
|
39
45
|
passages.size.times {where_arr << 'rowid between ? and ?'}
|
40
|
-
where_arr
|
46
|
+
where_arr = [or_join_where(where_arr)]
|
41
47
|
args = passages.map {|p| passage2rowids(p)}.flatten
|
42
48
|
end
|
43
49
|
searches.flatten.each do |o|
|
@@ -66,8 +72,12 @@ class Sqlbible
|
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
75
|
+
@bibles_dir = File.join(Dir.home, '.sqlbible/bibles')
|
76
|
+
|
69
77
|
class << self
|
70
78
|
|
79
|
+
attr_reader :bibles_dir
|
80
|
+
|
71
81
|
# Get the database schema as string
|
72
82
|
def db_schema
|
73
83
|
File.read(File.join(__dir__, '../schema.sql'))
|
@@ -96,6 +106,15 @@ class Sqlbible
|
|
96
106
|
select_schema_major_minor(db).join('.')
|
97
107
|
end
|
98
108
|
|
109
|
+
def resolve_db_filename db_name
|
110
|
+
fn = db_name.to_s
|
111
|
+
if File.basename(fn) == fn
|
112
|
+
File.join(bibles_dir, format('%s.sqlbible', fn.sub(/\.sqlbible$/, '')))
|
113
|
+
else
|
114
|
+
fn
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
99
118
|
end
|
100
119
|
|
101
120
|
private
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlbible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
|
+
original_platform: ''
|
6
7
|
authors:
|
7
8
|
- Jan Friedrich
|
8
9
|
bindir: bin
|
9
10
|
cert_chain: []
|
10
|
-
date: 2024-
|
11
|
+
date: 2024-12-13 00:00:00.000000000 Z
|
11
12
|
dependencies:
|
12
13
|
- !ruby/object:Gem::Dependency
|
13
14
|
name: nokogiri
|