Class: SafeDb::Import
- Inherits:
-
Controller
- Object
- Controller
- SafeDb::Import
- Defined in:
- lib/controller/book/import.rb
Overview
The import use case takes a filepath parameter in order to pull in a json formatted data structure. It then proceeds to merge each chapter of the source JSON structure into the corresponding chapter of the destination, handling duplicate key/value pairs in a sensible way.
Instance Attribute Summary collapse
-
#import_filepath ⇒ Object
writeonly
Sets the attribute import_filepath.
Instance Method Summary collapse
-
#execute ⇒ Object
The import use case takes a filepath parameter in order to pull in a json formatted data structure.
Methods inherited from Controller
#check_post_conditions, #check_pre_conditions, #flow, #initialize, #open_remote_backend_location, #post_validation, #pre_validation, #read_verse, #set_verse, #update_verse
Constructor Details
This class inherits a constructor from SafeDb::Controller
Instance Attribute Details
#import_filepath=(value) ⇒ Object (writeonly)
Sets the attribute import_filepath
12 13 14 |
# File 'lib/controller/book/import.rb', line 12 def import_filepath=(value) @import_filepath = value end |
Instance Method Details
#execute ⇒ Object
The import use case takes a filepath parameter in order to pull in a json formatted data structure. It then proceeds to merge each chapter of the source JSON structure into the corresponding chapter of the destination, handling duplicate key/value pairs in a sensible way.
18 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 |
# File 'lib/controller/book/import.rb', line 18 def execute abort "Cannot find the import file at path #{@import_filepath}" unless File.exists?( @import_filepath ) puts "" puts "### #############################################################\n" puts "--- -------------------------------------------------------------\n" puts "" puts " Book Name := #{@book.book_name()}\n" puts " Book Id := #{@book.book_id()}\n" puts " Import from := #{@import_filepath}\n" puts " Import time := #{TimeStamp.readable()}\n" puts "" new_verse_count = 0 data_store = DataStore.from_json( File.read( @import_filepath ) ) data_store.each_pair do | chapter_name, chapter_data | @book.import_chapter( chapter_name, chapter_data ) new_verse_count += chapter_data.length() end @book.write() puts "" puts "#{data_store.length()} chapters and #{new_verse_count} verses were successfully imported.\n" puts "" end |