Class: SafeDb::Export
- Inherits:
-
Controller
- Object
- Controller
- SafeDb::Export
- Defined in:
- lib/controller/book/export.rb
Overview
Export one, some or all chapters, verses and lines within the logged in book.
Aspirational Feature
The –print flag demands that the exported text goes to stdout otherwise it will be placed in an aptly named file in the present working directory.
Instance Method Summary collapse
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 Method Details
#execute ⇒ Object
13 14 15 16 17 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 47 48 49 50 51 52 53 54 |
# File 'lib/controller/book/export.rb', line 13 def execute puts "" puts "### #############################################################\n" puts "--- --------------------------------------------------------------\n" puts "" puts " The Birthday := #{@book.init_time()}\n" puts " Book Name := #{@book.book_name()}\n" puts " Book Id := #{@book.book_id()}\n" puts " Open Chapter := #{@book.get_open_chapter_name()}\n" if @book.has_open_chapter_name?() puts " Open Verse := #{@book.get_open_verse_name()}\n" if @book.has_open_verse_name?() puts "" export_filename = "safedb.#{TimeStamp.yyjjj_hhmm_ss_nanosec()}.#{@book.book_id()}.json" export_filepath = File.join( Dir.pwd, export_filename ) exported_struct = {} verse_count = 0 @book.branch_chapter_keys().each_pair do | chapter_name, chapter_keys | chapter_data = Content.unlock_branch_chapter( chapter_keys ) verse_count += chapter_data.length exported_struct.store( chapter_name, chapter_data ) end File.write( export_filepath, JSON.pretty_generate( exported_struct ) + "\n" ) puts "" puts "Number of chapters exported >> #{@book.chapter_count()}" puts "Number of verses exported >> #{verse_count}" puts "The export filename is #{export_filename}" puts "The Present Working Directory is #{Dir.pwd}" puts "" puts "--- --------------------------------------------------------------\n" puts "### #############################################################\n" puts "" end |