class Pcoder::Processor

Public Class Methods

new() click to toggle source
# File lib/pcoder.rb, line 105
def initialize
  @opts = {}
end

Public Instance Methods

parse_options() click to toggle source
# File lib/pcoder.rb, line 121
def parse_options
  opt = OptionParser.new
  opt.banner = "#{File.basename($0)} [file...]"
  opt.on("-t Task", "Set contest task name.") {|v| @opts[:task] = v }
  opt.on("--proxy Proxy", "Set proxy host. Example: \[ --proxy proxy.example.com:8080 \]") {|v| @opts[:proxy] = v }
  opt.on("-h", "--help", "Display Help.") do
    puts opt.help
    exit
  end
  opt.parse!(ARGV)
end
run(path = ARGV[0], this = self, atcoder = Atcoder.new, source = nil) click to toggle source
# File lib/pcoder.rb, line 109
def run(path = ARGV[0], this = self, atcoder = Atcoder.new, source = nil)
  exit_with_message("Please specify a file and try agein.") if path.nil?
  user = this.enter_username
  pass = this.enter_password
  source ||= SourceCode.new(path)
  host = contest_host(source.basename)
  atcoder.login(user, pass, host)
  atcoder.set_proxy(@opts[:proxy]) if @opts[:proxy]
  source.set_task_option(@opts[:task]) if @opts[:task]
  puts "Successfully uploaded." if atcoder.submit(source)
end

Protected Instance Methods

contest_host(basename) click to toggle source
# File lib/pcoder.rb, line 148
def contest_host(basename)
  sub_domain = (@opts[:task] || basename ).split("_").first
  "#{sub_domain}.#{ATCODER_HOST}"
end
enter_password() click to toggle source
# File lib/pcoder.rb, line 144
def enter_password
  HighLine.new.ask("Password: ") { |q| q.echo = "*" }
end
enter_username() click to toggle source
# File lib/pcoder.rb, line 140
def enter_username
  HighLine.new.ask("Username: ")
end
exit_with_message(mes) click to toggle source
# File lib/pcoder.rb, line 135
def exit_with_message(mes)
  puts mes
  exit
end