Class: Judges::Update

Inherits:
Object
  • Object
show all
Defined in:
lib/judges/update.rb

Overview

Update.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(loog) ⇒ Update

Returns a new instance of Update.



32
33
34
# File 'lib/judges/update.rb', line 32

def initialize(loog)
  @loog = loog
end

Instance Method Details

#run(_opts, args) ⇒ Object



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

def run(_opts, args)
  raise 'Exactly two arguments required' unless args.size == 2
  dir = args[0]
  file = args[1]
  fb = Factbase.new
  if File.exist?(file)
    fb.import(File.read(file))
    @loog.info("Factbase imported from #{file} (#{File.size(file)} bytes)")
  else
    @loog.info("There is no Factbase to import from #{file}")
  end
  done = Judges::Packs.new(dir).each_with_index do |p, i|
    @loog.info("Pack ##{i} found in #{p.dir}")
    p.run(fb, {})
  end
  @loog.info("#{done} judges processed")
  File.write(file, fb.export)
  @loog.info("Factbase exported to #{file} (#{File.size(file)} bytes)")
end