sqlbible 1.1.0 → 1.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: 0db4b2a65f0c016b81b2d1ec4c0cb45c85bb619eacf7aa802cea2fcfda88048c
4
- data.tar.gz: 61e97c6905189eec0a5cfc6ef1b02a8cc91dd1d4ecd1fe1d9250db1c9c93c423
3
+ metadata.gz: '095b3bc9b6735cd1df572c88d96117b96a60ebfc2bd928c01d8ef1bf5b2c5881'
4
+ data.tar.gz: 2c9cd72e62e96e81bb210e1416c660e974a24fc17018edc8165b383c74e73083
5
5
  SHA512:
6
- metadata.gz: 7ba9e92407bc21109d36538b6932b04790a0d6082ca6131260280b6aaaf2b96e3bf42872d352637c8846ebb4d28999da222b0130a30ac41e47414d36684bd09a
7
- data.tar.gz: c5250da5c011c5e4fb1e5f3536be717a84c550f9f10dd8c03d2665cdb369982aaa4fbab4d83a183010245621dda4cf092f05746f05f61c4349507dd96d1a4b5d
6
+ metadata.gz: c7abadece71c1c11a3fddf7d5949e78c507ca6b74d309030d15cdd840329b08fb40af572440e3fa36430604e66ad95e952e2e46b4f3305495c5031384a869ddc
7
+ data.tar.gz: 7c568ebde272045cba9b9f8b2a23a06d2d1b8ee381ca3abeb853e7b123beaeb1598ab6323ac485e8b59d5330545e9350189975f3c11d5092a97271c480f005eb
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 use well with Scripref references and passages
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,21 @@ require 'scripref'
7
7
  require 'sqlbible'
8
8
 
9
9
  result = OptimistXL.options do
10
- synopsis 'Usage: sqlitebible [options] [<command> [suboptions] <filename>]'
10
+ synopsis 'Usage: sqlbible [options] [<command> [suboptions] <filename>]'
11
11
  subcmd :convert, 'Convert a bible from OSIS-XML to Sqlbible format' do
12
- opt :output, 'Output filename of the generated Sqlbible file', type: String
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
15
+ subcmd :list, 'Show a list of the names of the bibles in central directory'
14
16
  subcmd :search, 'Search with regular expressions' do
17
+ opt :name, 'Name of the bible module filename of an .sqlbible file', type: String
15
18
  opt :search, 'Regular expression to search (multiple allowed)', type: String, multi: true, required: true
16
19
  opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: 'en'
17
20
  opt :output, 'Output filename', type: String
18
21
  opt :range, 'Search range, example: "John 1-10"', type: String
19
22
  end
20
23
  subcmd :text, 'Show text of references' do
24
+ opt :name, 'Name of the bible module filename of an .sqlbible file', type: String
21
25
  opt :lang, 'Language for parsing and formatting scripture references', type: String, permitted: %w(de en), default: 'en'
22
26
  opt :output, 'Output filename', type: String
23
27
  opt :reference, 'Reference to show, example: "John 3:16; 10:27-30"', type: String, required: true
@@ -25,11 +29,6 @@ result = OptimistXL.options do
25
29
  version format("sqlbible %s\nschema version %s", Sqlbible::VERSION, Sqlbible.schema_version)
26
30
  end
27
31
 
28
- unless filename = result.leftovers.first
29
- $stderr.puts 'no filename given'
30
- exit 1
31
- end
32
-
33
32
  def determine_lang_mod subopts
34
33
  case l = subopts[:lang]
35
34
  when 'en', nil
@@ -57,14 +56,29 @@ subopts = result.subcommand_options
57
56
 
58
57
  case result.subcommand
59
58
  when 'convert'
59
+ require 'fileutils'
60
60
  require 'sqlbible/convert'
61
- osis_fn = filename
62
- sqlite_fn = subopts[:output] || osis_fn.sub(/\.xml/i, '') << '.sqlite'
61
+ unless osis_fn = result.leftovers.first
62
+ $stderr.puts 'no filename given'
63
+ exit 1
64
+ end
65
+ sqlbible_fn = Sqlbible.resolve_db_filename(subopts[:name])
66
+ if !subopts[:overwrite] && File.exist?(sqlbible_fn)
67
+ $stderr.puts format('file %s exist, conversion aborted', sqlbible_fn)
68
+ exit 1
69
+ end
70
+ unless File.exist?(dir = Sqlbible.bibles_dir)
71
+ puts format('create directory %s', dir)
72
+ FileUtils.mkdir_p dir
73
+ end
63
74
  if $stdout.tty?
64
- puts "convert #{osis_fn} to #{sqlite_fn} ..."
75
+ puts "convert #{osis_fn} to #{sqlbible_fn} ..."
65
76
  end
66
- Sqlbible.convert osis_fn, sqlite_fn
77
+ Sqlbible.convert osis_fn, sqlbible_fn
67
78
  exit
79
+ when 'list'
80
+ puts 'Available bible names:'
81
+ puts Sqlbible.bible_names.join("\n")
68
82
  when 'search'
69
83
  searches = subopts[:search]
70
84
  lang_mod = determine_lang_mod(subopts)
@@ -74,8 +88,8 @@ when 'search'
74
88
  else
75
89
  range = nil
76
90
  end
77
- out = determine_out subopts
78
- bible = Sqlbible.new(filename)
91
+ out = determine_out(subopts)
92
+ bible = Sqlbible.new(subopts[:name])
79
93
  regexes = searches.map {|s| Regexp.new(s)}
80
94
  f = Scripref::Formatter.new(lang_mod, bookformat: :abbrev)
81
95
  bible.search(regexes, range: range).each do |v|
@@ -86,7 +100,7 @@ when 'text'
86
100
  p = Scripref::Parser.new(lang_mod)
87
101
  f = Scripref::Formatter.new(lang_mod, bookformat: :abbrev)
88
102
  ref = p.parse(subopts[:reference])
89
- bible = Sqlbible.new(filename)
103
+ bible = Sqlbible.new(subopts[:name])
90
104
  out = determine_out subopts
91
105
  bible.reference(ref).flatten.each do |v|
92
106
  out.puts format_verse(f, v)
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  class Sqlbible
5
- VERSION = '1.1.0'
5
+ VERSION = '1.3.0'
6
6
  end
data/lib/sqlbible.rb CHANGED
@@ -8,8 +8,14 @@ require_relative 'sqlbible/version'
8
8
 
9
9
  class Sqlbible
10
10
 
11
- def initialize db_filename
12
- @db = SQLite3::Database.new(db_filename)
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 == [or_join_where(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,13 +72,24 @@ 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'))
74
84
  end
75
85
 
86
+ # Get a list of the names of the bibles in bibles_dir
87
+ def bible_names
88
+ Dir.chdir bibles_dir do
89
+ Dir['*.sqlbible'].map {|fn| fn.sub(/\.sqlbible$/, '')}.sort
90
+ end
91
+ end
92
+
76
93
  # Get an array of the major and minor version of the database schema of the
77
94
  # actual version of the lib
78
95
  def schema_major_minor
@@ -96,6 +113,15 @@ class Sqlbible
96
113
  select_schema_major_minor(db).join('.')
97
114
  end
98
115
 
116
+ def resolve_db_filename db_name
117
+ fn = db_name.to_s
118
+ if File.basename(fn) == fn
119
+ File.join(bibles_dir, format('%s.sqlbible', fn.sub(/\.sqlbible$/, '')))
120
+ else
121
+ fn
122
+ end
123
+ end
124
+
99
125
  end
100
126
 
101
127
  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.1.0
4
+ version: 1.3.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-07 00:00:00.000000000 Z
11
+ date: 2024-12-13 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: nokogiri