Class: Judges::Judges
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-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#each {|Judge| ... } ⇒ Object
Iterate over them all.
-
#each_with_index {|(Judge, Integer)| ... } ⇒ Object
Iterate over them all.
-
#get(name) ⇒ Judge
Get one judge by name.
-
#initialize(dir, lib, loog, start: Time.now, shuffle: '') ⇒ Judges
constructor
A new instance of Judges.
Constructor Details
#initialize(dir, lib, loog, start: Time.now, shuffle: '') ⇒ Judges
Returns a new instance of Judges.
29 30 31 32 33 34 35 |
# File 'lib/judges/judges.rb', line 29 def initialize(dir, lib, loog, start: Time.now, shuffle: '') @dir = dir @lib = lib @loog = loog @start = start @shuffle = shuffle || '' end |
Instance Method Details
#each {|Judge| ... } ⇒ Object
Iterate over them all.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/judges/judges.rb', line 47 def each(&) return to_enum(__method__) unless block_given? list = Dir.glob(File.join(@dir, '*')).each.to_a.map do |d| next unless File.directory?(d) b = File.basename(d) next unless File.exist?(File.join(d, "#{b}.rb")) Judges::Judge.new(File.absolute_path(d), @lib, @loog) end list.compact! list.sort_by!(&:name) all = list.each_with_index.to_a good = all.dup all.reject { |a| a[0].name.start_with?(@shuffle) }.map { |a| a[1] }.each_with_index do |i, idx| good[i] = all[idx] end good.map { |a| a[0] }.each(&) end |
#each_with_index {|(Judge, Integer)| ... } ⇒ Object
Iterate over them all.
68 69 70 71 72 73 74 75 |
# File 'lib/judges/judges.rb', line 68 def each_with_index idx = 0 each do |p| yield [p, idx] idx += 1 end idx end |