Class: Judges::Import

Inherits:
Object show all
Defined in:
lib/judges/commands/import.rb

Overview

Import.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Import

Returns a new instance of Import.



34
35
36
# File 'lib/judges/commands/import.rb', line 34

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(_opts, args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/judges/commands/import.rb', line 38

def run(_opts, args)
  raise 'Exactly two arguments required' unless args.size == 2
  raise "File not found #{args[0].to_rel}" unless File.exist?(args[0])
  start = Time.now
  yaml = YAML.load_file(args[0], permitted_classes: [Time])
  impex = Judges::Impex.new(@loog, args[1])
  fb = impex.import(strict: false)
  fb = Factbase::Looged.new(fb, @loog)
  yaml.each do |i|
    f = fb.insert
    i.each do |p, v|
      f.send("#{p}=", v)
    end
  end
  impex.export(fb)
  @loog.info("Import finished in #{format('%.02f', Time.now - start)}s")
end