Class: Pcoder::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/pcoder.rb

Instance Method Summary collapse

Constructor Details

#initializeProcessor

Returns a new instance of Processor.



105
106
107
# File 'lib/pcoder.rb', line 105

def initialize
  @opts = {}
end

Instance Method Details

#parse_optionsObject



121
122
123
124
125
126
127
128
129
130
131
# 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) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# 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.(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