Class: Pcoder::Processor
- Inherits:
-
Object
- Object
- Pcoder::Processor
- Defined in:
- lib/pcoder.rb
Instance Method Summary collapse
-
#initialize ⇒ Processor
constructor
A new instance of Processor.
- #parse_options ⇒ Object
- #run(path = ARGV[0], this = self, atcoder = Atcoder.new, source = nil) ⇒ Object
Constructor Details
#initialize ⇒ Processor
Returns a new instance of Processor.
105 106 107 |
# File 'lib/pcoder.rb', line 105 def initialize @opts = {} end |
Instance Method Details
#parse_options ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/pcoder.rb', line 121 def opt = OptionParser.new opt. = "#{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) ("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 |