bomdb 0.1.0 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9e5b23505580c0871d836fffd14b2355a636562
4
- data.tar.gz: 7c31fa7627d57d7f6a179d21ad8ccab40dcc108d
3
+ metadata.gz: 50fee224307028e1d0970af931372cabad9a49a0
4
+ data.tar.gz: 63e2b95fee39540b9df7cf5ff836e3fe1342db34
5
5
  SHA512:
6
- metadata.gz: 69b236b5a23555654d6c2b311c7acd9f0c7767ff902957a50a0ed91db8c4c231b28e058e191f698ca840afbed8da02738cb3ffe9cc12d37cff009b71552f415b
7
- data.tar.gz: f3bff6acf0729645bbd90677a229db21db19fe59ea2adec262bd086318b16adf3e917ce503244b6f0cf6effb95d9a6c8b1b6c45ab91c8b1b9355ffaac4483a1d
6
+ metadata.gz: 5e78c010d8a87974ad21d3e8e03717105410f7ad429995dd3488bfbfdebbcc3b5f573b04733b1897bd56c92bfcb13ad99e02e46e4228e6babd77e72e053dab16
7
+ data.tar.gz: 03ff18efe84454627f25f841ce86db57fb528a834568580237de350cbeec69d5b2b879cc3eeab177fb6c7219b7db5110490900e4c66b3a3a0a0b22c56f058609
Binary file
@@ -9,8 +9,9 @@ module BomDB
9
9
 
10
10
 
11
11
  desc "import FILE", "import data from FILE into database, e.g. books.json"
12
- option :type, :type => :string, :default => nil
13
- option :format, :type => :string, :default => 'json'
12
+ option :type, :type => :string, :default => nil
13
+ option :format, :type => :string, :default => 'json'
14
+ option :edition, :type => :string, :default => nil
14
15
  def import(file)
15
16
  type = (options[:type] || type_from_file(file)).downcase
16
17
  format = (options[:format] || format_from_file(file)).downcase
@@ -20,7 +21,7 @@ module BomDB
20
21
  when 'books' then BomDB::Import::Books.new(BomDB.db)
21
22
  when 'verses' then BomDB::Import::Verses.new(BomDB.db)
22
23
  when 'editions' then BomDB::Import::Editions.new(BomDB.db)
23
- when 'contents' then BomDB::Import::Contents.new(BomDB.db)
24
+ when 'contents' then BomDB::Import::Contents.new(BomDB.db, edition_prefix: options[:edition])
24
25
  when 'refs' then BomDB::Import::Refs.new(BomDB.db)
25
26
  else
26
27
  puts "Unknown import type #{type}"
@@ -156,15 +157,40 @@ module BomDB
156
157
 
157
158
 
158
159
  desc "editions", "list available editions of the Book of Mormon"
159
- option :all, :type => :boolean, :default => false
160
+ option :all, :type => :boolean, :default => false,
161
+ :description => "Show all known editions, including those without content in BomDB"
162
+ option :"show-missing-verses", :type => :boolean, :default => false,
163
+ :description => "Lists missing verses in each edition (useful for fixing import errors)"
160
164
  def editions
161
- eds = BomDB.db[:editions].
165
+ BomDB.db[:editions].
162
166
  left_outer_join(:contents, :edition_id => :edition_id).
163
- select_group(:edition_name).
167
+ select_group(:editions__edition_id, :edition_name).
164
168
  select_append{ Sequel.as(count(:verse_id), :count) }.
165
169
  order(:edition_name).
166
- map { |r| "#{r[:count]} verses\t#{r[:edition_name]}" }
167
- puts eds.join("\n")
170
+ each do |r|
171
+ if r[:count] > 0 || options[:all]
172
+ puts "#{r[:count]} verses\t#{r[:edition_name]}"
173
+ end
174
+ if options[:"show-missing-verses"] && r[:count] > 0
175
+ BomDB.db[
176
+ "SELECT b.book_name, v.verse_chapter, v.verse_number " +
177
+ "FROM verses v " +
178
+ "JOIN books b ON v.book_id = b.book_id " +
179
+ "WHERE v.verse_heading IS NULL " +
180
+ "AND v.verse_id NOT IN " +
181
+ "(" +
182
+ " SELECT verse_id FROM contents c " +
183
+ " WHERE c.edition_id = ? " +
184
+ " AND c.verse_id = v.verse_id" +
185
+ ") " +
186
+ "ORDER BY b.book_sort, v.verse_chapter, v.verse_number",
187
+ r[:edition_id]
188
+ ].
189
+ each do |s|
190
+ puts " #{s[:book_name]} #{s[:verse_chapter]}:#{s[:verse_number]} missing"
191
+ end
192
+ end
193
+ end
168
194
  end
169
195
 
170
196
 
@@ -26,15 +26,21 @@ module BomDB
26
26
  )
27
27
  end
28
28
 
29
- case format
30
- when 'json' then import_json(ensure_parsed_json(data))
31
- when 'text' then import_text(data)
32
- else
33
- return Import::Result.new(
34
- success: false,
35
- error: "Unknown format: #{format}"
36
- )
37
- end
29
+ import_before() if respond_to?(:import_before)
30
+
31
+ result = case format
32
+ when 'json' then import_json(ensure_parsed_json(data))
33
+ when 'text' then import_text(data)
34
+ else
35
+ return Import::Result.new(
36
+ success: false,
37
+ error: "Unknown format: #{format}"
38
+ )
39
+ end
40
+
41
+ import_after() if respond_to?(:import_after)
42
+
43
+ result
38
44
  end
39
45
 
40
46
  def ensure_parsed_json(data)
@@ -5,12 +5,23 @@ module BomDB
5
5
  module Import
6
6
  class Contents < Import::Base
7
7
  tables :books, :verses, :editions, :contents
8
- DEFAULT_VERSE_CONTENT_RE = /^\s*(.+)(\d+):(\d+)\s*(.*)$/
9
- DEFAULT_VERSE_REF_RE = /^([^:]+)\s+(\d+):(\d+)$/
8
+ DEFAULT_VERSE_CONTENT_RE = /^\s*(.+)\s+(\d+):(\d+)\s+(.*)$/
9
+ DEFAULT_VERSE_REF_RE = /^\s*(.+)\s+(\d+):(\d+)$/
10
10
 
11
11
  def import_text(data)
12
- if opts[:edition_id].nil?
13
- raise ArgumentError, "Edition is required for text import of contents"
12
+ if opts[:edition_prefix].nil?
13
+ return Import::Result.new(success: false,
14
+ error: "'--edition' is required for text import of contents"
15
+ )
16
+ end
17
+
18
+ edition_model = Models::Edition.new(@db)
19
+
20
+ edition = edition_model.find(opts[:edition_prefix])
21
+ if edition.nil?
22
+ return Import::Result.new(success: false,
23
+ error: "Edition matching prefix '#{opts[:edition_prefix]}' not found"
24
+ )
14
25
  end
15
26
 
16
27
  verse_re = opts[:verse_re] || DEFAULT_VERSE_CONTENT_RE
@@ -29,12 +40,13 @@ module BomDB
29
40
  )
30
41
 
31
42
  @db[:contents].insert(
32
- edition_id: opts[:edition_id],
43
+ edition_id: edition[:edition_id],
33
44
  verse_id: verse_id,
34
45
  content_body: content
35
46
  )
36
47
  end
37
48
  end
49
+ Import::Result.new(success: true)
38
50
  end
39
51
 
40
52
  def import_json(data)
@@ -1,3 +1,3 @@
1
1
  module BomDB
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bomdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duane Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-11 00:00:00.000000000 Z
11
+ date: 2015-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel