Class: BomDB::Import::Refs
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#import_json(data, **args) ⇒ Object
Expected data format is: { (ref_name:String): [ { “book”:String,“chapter”:Int,“verse”:Int, “ref_book”:String,“ref_chapter”:Int,“ref_verse”:Int, “is_parallel”:Bool,“is_quotation”:Bool } … ] }.
Methods inherited from Base
#ensure_parsed_json, #import, #initialize, #schema, tables, #tables
Constructor Details
This class inherits a constructor from BomDB::Import::Base
Instance Method Details
#import_json(data, **args) ⇒ Object
Expected data format is: {
(ref_name:String): [
{
"book":String,"chapter":Int,"verse":Int,
"ref_book":String,"ref_chapter":Int,"ref_verse":Int,
"is_parallel":Bool,"is_quotation":Bool
}
...
]
}
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bomdb/import/refs.rb', line 19 def import_json(data, **args) data.each_pair do |ref_name, rows| rows.each do |r| verse = @db[:verses]. join(:books, :book_id => :book_id). where( book_name: r['book'], verse_chapter: r['chapter'], verse_number: r['verse'], verse_heading: nil). first if verse.nil? return Import::Result.new( success: false, error: "Unable to find verse #{r['book']} #{r['chapter']}:#{r['verse']}" ) end @db[:refs].insert( verse_id: verse[:verse_id], ref_name: ref_name, ref_book: r['ref_book'], ref_chapter: r['ref_chapter'], ref_verse: r['ref_verse'], ref_is_parallel: r['is_parallel'], ref_is_quotation: r['is_quotation'] ) end end Import::Result.new(success: true) rescue Sequel::UniqueConstraintViolation => e Import::Result.new(success: false, error: e) end |