Class: Judges::Impex
Overview
Import/Export of factbases.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
- #export(fb) ⇒ Object
- #import(strict: true) ⇒ Object
- #import_to(fb) ⇒ Object
-
#initialize(loog, file) ⇒ Impex
constructor
A new instance of Impex.
Constructor Details
#initialize(loog, file) ⇒ Impex
Returns a new instance of Impex.
33 34 35 36 |
# File 'lib/judges/impex.rb', line 33 def initialize(loog, file) @loog = loog @file = file end |
Instance Method Details
#export(fb) ⇒ Object
55 56 57 58 59 |
# File 'lib/judges/impex.rb', line 55 def export(fb) FileUtils.mkdir_p(File.dirname(@file)) File.binwrite(@file, fb.export) @loog.info("Factbase exported to #{@file.to_rel} (#{File.size(@file)} bytes)") end |
#import(strict: true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/judges/impex.rb', line 38 def import(strict: true) fb = Factbase.new if File.exist?(@file) fb.import(File.binread(@file)) @loog.info("The factbase imported from #{@file.to_rel} (#{File.size(@file)} bytes)") elsif strict raise "The factbase is absent at #{@file.to_rel}" end fb end |
#import_to(fb) ⇒ Object
49 50 51 52 53 |
# File 'lib/judges/impex.rb', line 49 def import_to(fb) raise "The factbase is absent at #{@file.to_rel}" unless File.exist?(@file) fb.import(File.binread(@file)) @loog.info("The factbase loaded from #{@file.to_rel} (#{File.size(@file)} bytes)") end |