Class: Judges::Options

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

Overview

Options for Ruby scripts in the judges.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(pairs = nil) ⇒ Options

Ctor.

Parameters:

  • pairs (Array<String>) (defaults to: nil)

    List of pairs, like [“token=af73cd3”, “max_speed=1”]



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

def initialize(pairs = nil)
  @pairs = pairs
end

Instance Method Details

#+(other) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/judges/options.rb', line 42

def +(other)
  touch # this will trigger method_missing() method, which will create @hash
  h = @hash.dup
  other.touch # this will trigger method_missing() method, which will create @hash
  other.instance_variable_get(:@hash).each do |k, v|
    h[k] = v
  end
  Judges::Options.new(h.map { |k, v| "#{k}=#{v}" })
end

#empty?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/judges/options.rb', line 37

def empty?
  touch # this will trigger method_missing() method, which will create @hash
  @hash.empty?
end

#to_sObject

Convert them all to a string (printable in a log).



53
54
55
56
57
58
59
60
# File 'lib/judges/options.rb', line 53

def to_s
  touch # this will trigger method_missing() method, which will create @hash
  @hash.map do |k, v|
    v = v.to_s
    v = "#{v[0..3]}#{'*' * (v.length - 4)}" if v.length > 8
    "#{k} → \"#{v}\""
  end.join("\n")
end