Class: Judges::Judges

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

Overview

Collection of all judges to run.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(dir, lib, loog) ⇒ Judges

Returns a new instance of Judges.



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

def initialize(dir, lib, loog)
  @dir = dir
  @lib = lib
  @loog = loog
end

Instance Method Details

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

Iterate over them all.

Yields:



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

def each
  Dir.glob(File.join(@dir, '**/*.rb')).each do |f|
    d = File.dirname(File.absolute_path(f))
    yield Judges::Judge.new(d, @lib, @loog)
  end
end

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

Iterate over them all.

Yields:



56
57
58
59
60
61
62
63
# File 'lib/judges/judges.rb', line 56

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:



39
40
41
42
43
# File 'lib/judges/judges.rb', line 39

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)
end