Class: Contest::Driver::DriverBase

Inherits:
DriverEvent show all
Defined in:
lib/contest/driver/base.rb

Direct Known Subclasses

AizuOnlineJudge, Codeforces, UvaOnlineJudge

Instance Method Summary collapse

Methods inherited from DriverEvent

#initialize, #off, #on, #trigger

Constructor Details

This class inherits a constructor from Contest::Driver::DriverEvent

Instance Method Details

#define_options(&block) ⇒ Object



48
49
50
51
# File 'lib/contest/driver/base.rb', line 48

def define_options &block
  @blocks ||= []
  @blocks.push(block)
end

#get_commit_message(rule, status, options) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/contest/driver/base.rb', line 81

def get_commit_message rule, status, options
  message = rule
  message = message.gsub '${site}', get_site_name
  message = message.gsub '${problem-id}', get_problem_id(options)
  message = message.gsub '${status}', status
  message = "\n#{get_commit_message_ext}" unless get_commit_message_ext.nil?
  return message
end

#get_commit_message_extObject



77
78
79
# File 'lib/contest/driver/base.rb', line 77

def get_commit_message_ext
  nil
end

#get_descObject



44
45
46
# File 'lib/contest/driver/base.rb', line 44

def get_desc
  ''
end

#get_optsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/contest/driver/base.rb', line 53

def get_opts
  get_opts_ext
  define_options do
    opt(
      :source,
      "Specify submitted code (Ex: main.cpp)",
      :type => :string,
      :required => false,
    )
    opt(
      :language,
      "Specify programming language (Ex: C++, Java or etc...)",
      :type => :string,
      :required => false,
    )
  end
  Trollop::options ARGV, @blocks do |blocks|
    version "git-contest driver"
    blocks.each do |b|
      instance_eval &b
    end
  end
end

#get_opts_extObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/contest/driver/base.rb', line 15

def get_opts_ext
  # Example:
  # define_options do
  #   opt(
  #     :problem_id,
  #     "Problem ID (Ex: 1000, 123, 0123, etc...)",
  #     :type => :string,
  #     :required => true,
  #   )
  # end
  raise 'TODO: Implement'
end

#get_problem_id(options) ⇒ Object



32
33
34
# File 'lib/contest/driver/base.rb', line 32

def get_problem_id(options)
  raise 'TODO: Implement'
end

#get_site_nameObject



28
29
30
# File 'lib/contest/driver/base.rb', line 28

def get_site_name
  raise 'TODO: Implement'
end

#resolve_language(label) ⇒ Object



36
37
38
# File 'lib/contest/driver/base.rb', line 36

def resolve_language(label)
  raise 'TODO: Implement'
end

#submit(config, source_path, options) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/contest/driver/base.rb', line 90

def submit(config, source_path, options)
  $config = get_config
  $config["submit_rules"] ||= {}
  $config["submit_rules"]["message"] ||= "${site} ${problem-id}: ${status}"
  source_path = Utils.resolve_path(options[:source] || $config["submit_rules"]["source"] || source_path)
  options[:source] = source_path
  options[:language] ||= Utils.resolve_language(source_path)
  options[:language] = resolve_language Utils.normalize_language(options[:language])
  status = submit_ext(config, source_path, options)
  get_commit_message($config["submit_rules"]["message"], status, options)
end

#submit_ext(config, source_path, options) ⇒ Object



40
41
42
# File 'lib/contest/driver/base.rb', line 40

def submit_ext(config, source_path, options)
  raise 'TODO: Implement'
end