Class: BomDB::Import::Books
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#import_json(data) ⇒ Object
Expected data format is: [ [book_name:String, book_group:String, book_sort:Integer], … ].
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) ⇒ Object
Expected data format is: [
[book_name:String, book_group:String, book_sort:Integer],
...
]
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bomdb/import/books.rb', line 13 def import_json(data) data.each do |name, group, sort| @db[:books].insert( book_name: name, book_group: group, book_sort: sort ) end Import::Result.new(success: true) rescue Sequel::UniqueConstraintViolation => e Import::Result.new(success: false, error: e) end |