sqlbible 1.3.4 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21260f096b6235ac423d8406a10afe1b83f39765585bb3788489877da458c7d5
4
- data.tar.gz: 747c638f0ed836cf25995b7b58659c79501bacb0b5d1e8198e5ef29d6b1aeab1
3
+ metadata.gz: 9144e85f267eec314b61068b039076e589025526127b82b1b1c02c25609a60f3
4
+ data.tar.gz: 567c83c7648b8fe2ee9a155adf65d26c983136aff3df9baf517824c0236747e4
5
5
  SHA512:
6
- metadata.gz: a6ff9efb6a3d602bfde16a4824ef8b92fa4e19d6f71d7fac7c8e7d06365b66540f23026d4bd945c879563910734eb860b595ffc4e19faa0b9d7ed38f5e0658d7
7
- data.tar.gz: f46ccb07c1abad4264d31fdf5189a1e0ec60f95a3649bf7b8234733662a59a45ca6e77b743622b89a217af54e5230e95bfba32b9984ce9c2a832df2b1326c52d
6
+ metadata.gz: a5d0ec2cb0912d1f8d4f8dc89b0f8fce44ecff9891bb7221642846ae643be69a759763f1fa4a64056daac17cd2608019be8da05d86745ac44d9594bce08a7041
7
+ data.tar.gz: e4c1bc126b71e3e99bad390c74b1bda20e932b8360235e651c86d3cdd9ec5cd9768f56e165cd339c473976f2188dffca0f5caedad7972b35949f3276cb744fd7
data/bin/sqlbible CHANGED
@@ -6,6 +6,11 @@ require 'optimist_xl'
6
6
  require 'scripref'
7
7
  require 'sqlbible'
8
8
 
9
+ default_bible_param = {}
10
+ if b = Sqlbible.bible
11
+ default_bible_param[:default] = b.to_s
12
+ end
13
+
9
14
  result = OptimistXL.options do
10
15
  synopsis 'Usage: sqlbible <command> [options] [filename]?'
11
16
  subcmd :convert, 'Convert a bible from OSIS-XML to Sqlbible format' do
@@ -14,15 +19,15 @@ result = OptimistXL.options do
14
19
  end
15
20
  subcmd :list, 'Show a list of the names of the bibles in central directory'
16
21
  subcmd :search, 'Search with regular expressions' do
17
- opt :bible, 'Name of the bible module filename of an .sqlbible file', type: String
22
+ opt :bible, 'Name of the bible module filename of an .sqlbible file', type: String, **default_bible_param
18
23
  opt :search, 'Regular expression to search (multiple allowed)', type: String, multi: true, required: true
19
- opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: 'en'
24
+ opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: Sqlbible.lang.to_s
20
25
  opt :output, 'Output filename', type: String
21
26
  opt :range, 'Search range, example: "John 1-10"', type: String
22
27
  end
23
28
  subcmd :text, 'Show text of references' do
24
- opt :bible, 'Name of the bible module filename of an .sqlbible file', type: String
25
- opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: 'en'
29
+ opt :bible, 'Name of the bible module filename of an .sqlbible file', type: String, **default_bible_param
30
+ opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: Sqlbible.lang.to_s
26
31
  opt :output, 'Output filename', type: String
27
32
  opt :reference, 'Reference to show, example: "John 3:16; 10:27-30"', type: String, required: true
28
33
  end
@@ -20,6 +20,7 @@ class Sqlbible
20
20
 
21
21
  doc.css('verse').each do |v|
22
22
  osisid = v['osisID']
23
+ next unless osisid
23
24
  bookid, chapter, verse = osisid.split('.')
24
25
  unless bookid == last_bookid
25
26
  booknumber += 1
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Sqlbible
5
- VERSION = '1.3.4'
5
+ VERSION = '1.5.0'
6
6
  end
data/lib/sqlbible.rb CHANGED
@@ -11,12 +11,19 @@ class Sqlbible
11
11
 
12
12
  attr_reader :db_filename
13
13
 
14
- def initialize db_name
14
+ def initialize db_name=Sqlbible.bible
15
15
  @db_filename = Sqlbible.resolve_db_filename(db_name, check_existence: true)
16
16
  @db = SQLite3::Database.new(@db_filename)
17
17
  @db.enable_load_extension(true)
18
18
  pcre_extension_file = ENV['SQLITE_PCRE_EXTENSION']
19
19
  @db.load_extension(pcre_extension_file) if pcre_extension_file
20
+ begin
21
+ @db.execute("select regexp('.', '.')")
22
+ rescue
23
+ @db.create_function 'regexp', 2 do |f, re, s|
24
+ f.result = s =~ /#{re}/
25
+ end
26
+ end
20
27
  check_schema_version
21
28
  end
22
29
 
@@ -71,10 +78,12 @@ class Sqlbible
71
78
  end
72
79
 
73
80
  @bibles_dir = File.join(Dir.home, '.sqlbible/bibles')
81
+ @lang = :en
74
82
 
75
83
  class << self
76
84
 
77
85
  attr_reader :bibles_dir
86
+ attr_accessor :bible, :lang
78
87
 
79
88
  # Get the database schema as string
80
89
  def db_schema
@@ -131,6 +140,11 @@ class Sqlbible
131
140
  fn
132
141
  end
133
142
 
143
+ config_file = Dir[File.join(Dir.home, '.sqlbible/config{,.rb}')].first
144
+ if config_file && !ENV['NOSQLBIBLECONFIG']
145
+ load config_file
146
+ end
147
+
134
148
  end
135
149
 
136
150
  private
@@ -152,14 +166,33 @@ class Sqlbible
152
166
 
153
167
  def passage2rowids pass
154
168
  rowid1 = select_rowid(pass.b1, pass.c1, pass.v1, :asc)
169
+ unless rowid1
170
+ fail_book_chapter_verse pass.b1, pass.c1, pass.v1
171
+ end
155
172
  if rowid1 && pass.v2 == :f
156
173
  rowid2 = rowid1 + 1
157
174
  return [rowid1, rowid2]
158
175
  end
159
176
  rowid2 = select_rowid(pass.b2, pass.c2, pass.v2, :desc)
177
+ unless rowid2
178
+ fail_book_chapter_verse pass.b2, pass.c2, pass.v2
179
+ end
160
180
  [rowid1, rowid2]
161
181
  end
162
182
 
183
+ def fail_book_chapter_verse b, c, v
184
+ parts = []
185
+ parts << format('Passage for %s', b)
186
+ if c
187
+ parts << format(' chapter %d', c.to_i)
188
+ end
189
+ if v
190
+ parts << format(' verse %d', v.to_i)
191
+ end
192
+ parts << ' does not exist'
193
+ fail parts.join
194
+ end
195
+
163
196
  def select_rowid b, c, v, orderby
164
197
  cond = []
165
198
  args = []
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlbible
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-12-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: did_you_mean
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 3.7.0.dev
127
+ rubygems_version: 3.6.9
128
128
  specification_version: 4
129
129
  summary: Library for bibles as SQLite databases
130
130
  test_files: []