Class: Judges::Judges

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

Overview

Collection of all judges to run.

In the directory dir the following structure must be maintained:

dir/
  judge-one/
    judge-one.rb
    other files...
  judge-two/
    judge-two.rb
    other files...

The name of a directory of a judge must be exactly the same as the name of the .rb script inside the directory.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(dir, lib, loog, start: Time.now) ⇒ Judges

Returns a new instance of Judges.



46
47
48
49
50
51
# File 'lib/judges/judges.rb', line 46

def initialize(dir, lib, loog, start: Time.now)
  @dir = dir
  @lib = lib
  @loog = loog
  @start = start
end

Instance Method Details

#each {|Judge| ... } ⇒ Object

Iterate over them all.

Yields:



63
64
65
66
67
68
69
70
71
# File 'lib/judges/judges.rb', line 63

def each
  return to_enum(__method__) unless block_given?
  Dir.glob(File.join(@dir, '*')).each do |d|
    next unless File.directory?(d)
    b = File.basename(d)
    next unless File.exist?(File.join(d, "#{b}.rb"))
    yield Judges::Judge.new(File.absolute_path(d), @lib, @loog)
  end
end

#each_with_index {|(Judge, Integer)| ... } ⇒ Object

Iterate over them all.

Yields:



75
76
77
78
79
80
81
82
# File 'lib/judges/judges.rb', line 75

def each_with_index
  idx = 0
  each do |p|
    yield [p, idx]
    idx += 1
  end
  idx
end

#get(name) ⇒ Judge

Get one judge by name.

Returns:



55
56
57
58
59
# File 'lib/judges/judges.rb', line 55

def get(name)
  d = File.absolute_path(File.join(@dir, name))
  raise "Judge #{name} doesn't exist in #{@dir}" unless File.exist?(d)
  Judges::Judge.new(d, @lib, @loog, start: @start)
end