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-2026 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#each {|Judges::Judge| ... } ⇒ Enumerator
Iterates over all valid judges in the directory.
-
#each_with_index {|Judges::Judge, Integer| ... } ⇒ Integer
Iterates over all judges while tracking their index position.
-
#get(name) ⇒ Judges::Judge
Retrieves a specific judge by its name.
-
#initialize(dir, lib, loog, epoch: Time.now, shuffle: '', boost: [], demote: [], seed: 0) ⇒ Judges
constructor
Initialize.
Constructor Details
#initialize(dir, lib, loog, epoch: Time.now, shuffle: '', boost: [], demote: [], seed: 0) ⇒ Judges
Initialize.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/judges/judges.rb', line 38 def initialize(dir, lib, loog, epoch: Time.now, shuffle: '', boost: [], demote: [], seed: 0) @dir = dir @lib = lib @loog = loog @epoch = epoch @shuffle = shuffle || '' @boost = boost @demote = demote @seed = seed || 0 end |
Instance Method Details
#each {|Judges::Judge| ... } ⇒ Enumerator
Iterates over all valid judges in the directory.
This method discovers all judge directories, validates them (ensuring they contain a corresponding .rb file), and yields them in a specific order. The order is determined by:
-
Randomly reorder judges (if shuffle prefix is empty, shuffle all judges; if prefix is not empty, shuffle only those NOT starting with the prefix)
-
Judges whose names match the boost patterns are placed first (supports ‘*’ wildcards)
-
Judges whose names match the demote patterns are placed last (supports ‘*’ wildcards)
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/judges/judges.rb', line 74 def each(&) return to_enum(__method__) unless block_given? good = reorder_judges boosted = [] demoted = [] normal = [] good.each do |j| if fits?(j.name, @boost) boosted.append(j) elsif fits?(j.name, @demote) demoted.append(j) else normal.append(j) end end (boosted + normal + demoted).each(&) end |
#each_with_index {|Judges::Judge, Integer| ... } ⇒ Integer
Iterates over all judges while tracking their index position.
This method calls the #each method and additionally provides a zero-based index for each judge yielded. The judges are processed in the same order as determined by the #each method (with boost and shuffle rules applied).
100 101 102 103 104 105 106 107 |
# File 'lib/judges/judges.rb', line 100 def each_with_index idx = 0 each do |p| yield([p, idx]) idx += 1 end idx end |
#get(name) ⇒ Judges::Judge
Retrieves a specific judge by its name.
The judge must exist as a directory within the judges directory with the given name.
56 57 58 59 60 |
# File 'lib/judges/judges.rb', line 56 def get(name) d = File.absolute_path(File.join(@dir, name)) raise(StandardError, "Judge #{name} doesn't exist in #{@dir}") unless File.exist?(d) Judges::Judge.new(d, @lib, @loog, epoch: @epoch) end |